<>C/C++ The 11th Blue Bridge Cup provincial competition B Group 2

<> If there is a mistake, please point it out .

<>1. look for "2" answer :624
#include <iostream> #include <algorithm> using namespace std; int cnt(int num)
{ int ans=0; while(num) { if(num%10==2) ans++; num/=10; } return ans; } int main
() { int ans=0; for(int i=1;i<=2020;i++) ans+=cnt(i); cout<<ans<<endl; return 0;
}
<>2.gcd function , Directly answer :2481215
#include <iostream> #include <algorithm> using namespace std; int main() { int
ans=0; for(int i=1;i<=2020;i++) { for(int j=1;j<=2020;j++) { if(__gcd(i,j)==1)
ans++; } } cout<<ans<<endl; return 0; }
<>3. Serpentine answer :761

Hand counting is faster , Do some arithmetic series

<>4. run answer :8879
#include <iostream> #include <algorithm> using namespace std; int mon[13]={0,31
,28,31,30,31,30,31,31,30,31,30,31}; int main() { int y,m,d; cin>>y>>m>>d; int
ans=0; int flag=0; int week=6; // It is used to record the day of the week //i,j,k Enumeration date for(int i=2000;i<=y;i++
) { for(int j=1;j<=12;j++) { int End=mon[j]; if(((i%4==0&&i%100!=0)||i%400==0)
&& j==2) End++; for(int k=1;k<=End;k++) { ans++; if(week==1||k==1) ans++; if(++
week==8) week=1; if(i==y&&j==m&&k==d) { flag=1;break; } } if(flag==1) break; } }
cout<<ans<<endl; return 0; }
<>5. Lamp tube

This problem is calculated by hand , Figure it out 81, I don't know right or wrong ……

<>6. pass rate , rounding

I don't remember the function , Zoom in and out
#include <iostream> #include <algorithm> using namespace std; int n; void fun(
int &num) { if(num%10>4) { num/=10; num++; }else num/=10; } int main() { cin>>n;
int x; int cnt1=0; int cnt2=0; for(int i=0;i<n;i++) { cin>>x; if(x>=60) cnt1++;
if(x>=80) cnt2++; } int ans1=(cnt1*1.0/n*1.0)*1000; int ans2=(cnt2*1.0/n*1.0)*
1000; fun(ans1);fun(ans2); cout<<ans1<<"%"<<endl; cout<<ans2<<"%"<<endl; return
0; }
<>7. Next palindrome year

Enumerate years , Generate the corresponding month and day , Judging legitimacy
#include <iostream> #include <algorithm> #include <cstring> using namespace std
; int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char Input[10]; // Year of passage
The date of receipt At the same time, check whether the year is abab void getMD(int y,int &m,int &d,int &ab) { int temp[4]={0};
int i=0; while(y) { temp[i++]=y%10; y/=10; } m=temp[0]*10+temp[1]; d=temp[2]*10+
temp[3]; if(temp[0]==temp[2]&&temp[1]==temp[3]) ab=1; else ab=0; } // Check the legality of the day, month and day
bool check(int y,int m,int d) { if(((y%4==0&&y%100!=0)||y%400==0)&&m==2&&(d<1||d
>mon[2]+1)) return 0; if(m<1||m>12) return 0; if(d<1||d>mon[m]) return 0; return
1; } int main() { scanf("%s",&Input); int staY=0; int x=1; for(int i=3;i>=0;i--)
{ staY+=(Input[i]-'0')*x; x*=10; } int y1,m1,d1; int y2,m2,d2; int m,d,ab; int
flag=0; for(int i=staY+1;i<=9999;i++) { getMD(i,m,d,ab); if(check(i,m,d)) {
// The first time you find it, you won't find it again if(flag==0) { y1=i; m1=m; d1=d; flag=1; } if(ab==1) { y2=i; m2=m;
d2=d; break; } } } printf("%04d%02d%02d\n",y1,m1,d1); printf("%04d%02d%02d\n",y2
,m2,d2); return 0; }
<>8. Calculate the number of different letters in the interval , Subinterval of sum

Calculate the contribution value of each letter directly , Suppose that each interval is the first letter contribution , Then the contribution value of each letter is the length from the right to the end multiplied by the same letter that does not appear on the left
#include <iostream> #include <algorithm> #include <cstring> using namespace std
; typedef long long ll; string str; ll last[26]; // record 26 Last occurrence of letters ll ans=0;
int main() { for(int i=0;i<26;i++) last[i]=-1; cin>>str; ll len=str.size(); for(
ll i=0;i<len;i++) { ans+=(i-last[str[i]-'a'])*(len-i); last[str[i]-'a']=i; }
cout<<ans<<endl; return 0; }
<>9. Plane geometry , This is not the question , I learned to make up in the future

<>10. Construct reverse string , Priority shortest , Secondly, the lexicographic order is the smallest

In this question, I find the data of the past half of the regular water , In fact, I can't write . I don't want to post code to make a fool of myself

Technology
©2019-2020 Toolsou All rights reserved,
2020 year Java industry , General analysis of market environment and position Old farmer's tears : Nine iron rules of mixed workplace Database design use MySQL Processing 100 million level data 【 course 】 How to modify routing table ?vue project main.js usage method 【Java Details of knowledge points 3】 Serializable and Deserialize Renren from the perspective of Technology , Internet Marketing Python list , Yuanzu Aerial photography : Tesla Shanghai factory Model Y A large number of people have been offline