The meaning of the title: The title has already said it very clearly, so I won't repeat it.
Idea: Determine whether ((a*100)+i)%b is equal to 0, and if it is equal to 0, the counter will be incremented by 1.
Code:
#include<stdio.h> int main(void) { int a,b; int i; while(~scanf("%d%d",&a,&b)) { if(a==0&&b==0) break; int count = 0; for(i = 0; i <= 99; i++) { if(((a*100)+i)%b==0) count++; } printf("%d\n",count); } }
2. OCD 2 in WC
The meaning of the question: in a row of rice balls, each time you choose a rice ball larger than the front, how many can you choose at most?
Idea: Longest Ascending Subsequence Template Question
Code:
#include<stdio.h> const int MAX=1001; intmain() { int i,j; int a[MAX]; int dp[MAX]; int n; while(~scanf("%d",&n)) { for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { dp[i]=1; for(j=0;j<i;j++) { if(a[j]<a[i]&&dp[j]+1>dp[i]) dp[i]=dp[j]+1; } } int ans=0; for(i=0;i<n;i++) if(ans<dp[i]) ans=dp[i]; printf("%d\n",ans); } return 0; }
Question meaning: give 0, output 1; give 1, output 0;
Idea: give 0, output 1; give 1, output 0
Code:
#include<stdio.h> #include<string.h> int main(void) { int i; char s[201]; while(gets(s)!=NULL) { int len = strlen(s); for(i = 0; i < len; i++) { if(s[i]=='1') s[i] = '0'; else s[i] = '1'; } puts(s); } return 0; }
Title: It has been given in the title, so I won't repeat it
Idea: Four digits, each digit is modified to judge whether it is a perfect square number
Code:
#include<stdio.h> #include<math.h> bool f(int n) { int m; m = sqrt(n); if(m*m == n) return true; else return false; } int main(void) { int i; int t; scanf("%d",&t); int years = 1; while(t--) { int count = 0; int n; scanf("%d",&n); int a = n%10; int b = n/10%10; int c = n/100%10; int d = n/1000; for(i = -a; i < 10-a; i++) // try the ones if(f(n+i)) { count++; } for(i = -b*10; i < 100-10*b; i= i+10) //尝试十位 if(f(n+i)) { count++; } for(i = -c*100; i < 1000-100*c; i=i+100) //尝试百位 if(f(n+i)) { count++; } for(i = 1000-d*1000; i < 10000-1000*d; i=i+1000)//尝试千位 if(f(n+i)) { count++; } if(f(n)) printf("Case %d: %d\n",ans++,count-4); //If it is a perfect square, it needs -4, because the first four judgments are repeated else printf("Case %d: %d\n",ans++,count); } return 0; }