Blue Bridge Cup preparations (search + count)
count
What is a counting problem
Counting questions are a major type of question in OI, and they have become popular in various exams due to their high difficulty and less routines.
I. Base Count
real question
Blue Bridge Cup 2020 11th Provincial Competition Zhenti-Category Count
Question link: https://www.docpp.com/oj/problem2580.html
Topic description
Enter a string, please output how many uppercase letters, how many lowercase letters, and how many numbers the string contains.
enter
A line of input contains a string.
output
Output three lines, each with an integer representing the number of uppercase letters, lowercase letters, and numbers.
sample input
1 + a = Aab
Sample output
1
3
1
This question is simple, everyone should have done it once.
#include<bits/stdc++.h>
using namespace std;
int main(){
char s[10010];
cin>>s;
int a=0,b=0,c=0;
for(int i=0;i<strlen(s);i++){
if(s[i]>='0'&&s[i]<='9') c++;
else if(s[i]>='a'&&s[i]<='z') a++;
else if(s[i]>='A'&&s[i]<='Z') b++;
}
cout<<b<<endl;
cout<<a<<endl;
cout<<c<<endl;
}
multiple
Topic link: https://www.lanqiao.cn/problems/583/learning/
Question Description
This question is a fill-in-the-blank question. After calculating the result, use the output statement in the code to output the filled result.From 1 to 2020, how many numbers are both an integer multiple of 4 and an integer multiple of 6
#include <iostream>
using namespace std;
int main()
{
// 直接模拟
int ans=0;
for(int i=1;i<=2020;i++)
{
if(i%4==0&&i%6==0)
ans++;
}
cout<<ans<<endl;
return 0;
}
character count
Topic link: https://www.lanqiao.cn/problems/160/learning/topic
description
Given a word, count how many vowels and how many consonants are in the word.
There are five vowels including a, e, i, o, u, and the others are consonants.
Input format:
Enter a line containing one word containing only lowercase English letters. The number of letters in a word should not exceed 100.
output description
Two lines of output are output, the first containing an integer representing the number of vowels.
The second line contains an integer representing the number of consonants.
Input and output example
enter
lanqiao
output
4
3
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[])
{
char s[100];
int n=0,m=0,t=0;
cin>>s;
while(s[n]!='\0')
{
switch(s[n])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':m++;break;
default:t++;break;
}
n++;
}
printf("%d\n%d",m,t);// 请在此输入您的代码
return 0;
}
prime number
You can take a look at the blog prime number screening method written before: https://blog.csdn.net/qq_54729417/article/details/115708317?spm=1001.2014.3001.5502
Topic link: https://www.lanqiao.cn/problems/608/learning/
Question Description
This question is a fill-in-the-blank question. After calculating the result, use the output statement in the code to output the filled result.We know that the first prime number is 2, the second prime number is 3, the third prime number is 5...
Could you please calculate the 2019th prime number?
#include <iostream>
using namespace std;
//这里没有去使用欧拉速筛
int isprime(int x)
{
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
return 0;
}
return 1;
}
int ans=1;
int main()
{
for(int i=2;i<20000;i++)
{
if(ans==2019&&isprime(i))
cout<<i;
if(isprime(i))
{
ans++;
}
}
//cout<<"17569";
return 0;
}