For beginners, we recommend that you test the Blue Bridge cup online. Updating is not performed in order. When you are bored, you need to answer a few questions.
Http://lx.lanqiao.org/index.page
The recurrence formula of the Fibonacci series is: Fn = Fn-1 + Fn-2, where F1 = F2 = 1.
When n is large, Fn is very large. Now we want to know the remainder of Fn divided by 10007.
#include<cstdio>const int mod=10007;const int MAXN=1000000+10;int ans[MAXN];int main(){ ans[1]=ans[2]=1; int n; scanf("%d",&n); for(int i=3;i<=n;i++) ans[i]=(ans[i-1]+ans[i-2])%mod; printf("%d\n",ans[n]); return 0;}
Given the radius r of the circle, calculate the area of the circle.
#include<cstdio>#include<cmath>const double pi=acos(-1.0);int main(){double r;scanf("%lf",&r);printf("%.7lf\n",pi*r*r);return 0;}
Evaluate the value of 1 + 2 + 3 +... + n.
#include<cstdio>int main(){__int64 n;scanf("%I64d",&n);__int64 ans=(1+n)*n >>1;printf("%I64d\n",ans);return 0;}
Calculate a + B
#include <cstdio> int main(){ int a, b; scanf("%d%d", &a, &b); printf("%d", a+b); return 0;}
Sort
#include <cstdio>#include<algorithm>using namespace std;const int MAXN=200+10;int a[MAXN];int main(){ int n;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);printf("%d",a[0]);for(int i=1;i<n;i++)printf(" %d",a[i]);printf("\n"); return 0;}
Returns a series containing n integers. the first occurrence of integer a in the series is the nth.
#include <cstdio>const int MAXN=10000+10;int x[MAXN];int main(){int n,a;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&x[i]);scanf("%d",&a);int ans=-1;for(int i=1;i<=n;i++)if(x[i]==a){ans=i;break;}printf("%d\n",ans);return 0;}
Leap year judgment
#include <cstdio>int main(){ int n; scanf("%d",&n); if(n %4==0 && n%100!=0 || n%400==0) printf("yes\n"); else printf("no\n"); return 0;}
Given n hexadecimal positive integers, output the corresponding Octal numbers.
Train of Thought: first convert hexadecimal to 4-bit binary, and then the octal sequence can be obtained from every 3 digits of binary.
#include<cstdio>#include<cstring>const int MAXN=100000;char s[MAXN];char two[MAXN*4];int eight[MAXN*4];int main(){int T;scanf("%d",&T);while(T--){scanf("%s",s);int n=strlen(s),len=0;for(int i=0;i<n;i++){switch(s[i]){case '0':sprintf(two+len,"%s","0000");break;case '1':sprintf(two+len,"%s","0001");break;case '2':sprintf(two+len,"%s","0010");break;case '3':sprintf(two+len,"%s","0011");break;case '4':sprintf(two+len,"%s","0100");break;case '5':sprintf(two+len,"%s","0101");break;case '6':sprintf(two+len,"%s","0110");break;case '7':sprintf(two+len,"%s","0111");break;case '8':sprintf(two+len,"%s","1000");break;case '9':sprintf(two+len,"%s","1001");break;case 'A':sprintf(two+len,"%s","1010");break;case 'B':sprintf(two+len,"%s","1011");break;case 'C':sprintf(two+len,"%s","1100");break;case 'D':sprintf(two+len,"%s","1101");break;case 'E':sprintf(two+len,"%s","1110");break;case 'F':sprintf(two+len,"%s","1111");break;}len+=4;}//for(int i=0;i<len;i+=4)//printf("%c%c%c%c ",two[i],two[i+1],two[i+2],two[i+3]);int i=len-1,len2=0;for(i=len-1;i>=2;i-=3){eight[len2++]= two[i]-'0'+(two[i-1]-'0')*2+(two[i-2]-'0')*4;}if(i==2)eight[len2++]= two[i]-'0'+(two[i-1]-'0')*2+(two[i-2]-'0')*4;else if(i==1)eight[len2++]= two[i]-'0'+(two[i-1]-'0')*2;else if(i==0)eight[len2++]= two[i]-'0';i=len2-1;while(eight[i]==0)i--;for(;i>=0;i--)printf("%d",eight[i]);printf("\n");}return 0;}
Input a positive hexadecimal number string of no more than 8 digits from the keyboard, convert it to a positive decimal number, and then output it.
Note: 10 ~ 15 are represented by uppercase letters A, B, C, D, E, and F.
Idea: expand by right. Note that int is out of bounds when the range is 8 F.
#include<cstdio>#include<cstring>const int MAXN=10;char s[MAXN];int main(){while(~scanf("%s",s)){int n=strlen(s);__int64 ans=0,p=16;for(int i=0;i<n;i++){if(s[i]>='0' && s[i]<='9')ans=ans*p+(s[i]-'0');elseans=ans*p+(s[i]-'A'+10);}printf("%I64d\n",ans);}return 0;}
123321 is a very special number, which reads from the left and from the right is the same.
Enter a positive integer n to calculate all the five-and six-digit decimal numbers. The sum of the values is equal to n.
#include<cstdio>#include<cstring>char s[10];int main(){int n;scanf("%d",&n);for(int i=10000;i<1000000;i++){sprintf(s,"%d",i);int len=strlen(s);bool ok=true;for(int k=0;k<3;k++)if(s[k]!=s[len-k-1])ok=false;if(ok){int sum=0;for(int k=0;k<len;k++)sum+=s[k]-'0';if(sum==n)printf("%s\n",s);}}return 0;}
1221 is a very special number. It reads from the left and from the right is the same. It is programmed to calculate all such four-digit decimal numbers.
#include<cstdio>#include<cstring>char s[10];int main(){for(int i=1000;i<10000;i++){sprintf(s,"%d",i);int len=strlen(s);bool ok=true;for(int k=0;k<3;k++)if(s[k]!=s[len-k-1])ok=false;if(ok){printf("%s\n",s);}}return 0;}
153 is a very special number, which is equal to the Cube sum of each digit, that is, 153 = 1*1*1 + 5*5 + 3*3*3. Program all three decimal numbers that meet this condition
#include<cstdio>#include<cstring>char s[10];int main(){for(int i=100;i<1000;i++){sprintf(s,"%d",i);int sum=0;for(int k=0;k<3;k++){int x=s[k]-'0';sum+=x*x*x;}if(sum==i)printf("%d\n",i);}return 0;}
Returns n numbers to find the maximum, minimum, and sum of n numbers.
PS: the example of the question is wrong. And
#include<cstdio>const int INF=10000+10;int main(){int n,min=INF,max=-INF,sum=0,temp;scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&temp);sum+=temp;if(max <temp)max=temp;if(min >temp)min=temp;}printf("%d\n%d\n%d\n",max,min,sum);return 0;}