2022 海选女主角
1 #include2 #include 3 4 int main(){ 5 int s[50][50]; 6 int n,m,x,y,z,i,j; 7 while(scanf("%d %d",&m,&n)!=EOF){ 8 for(x=1;x<=m;x++){ 9 for(y=1;y<=n;y++){scanf("%d",&s[x][y]);} 10 } 11 z = 0; 12 for(x=1;x<=m;x++){ 13 for(y=1;y<=n;y++){ 14 if(z abs(s[x][y]);} 15 } 16 } 17 printf("%d %d %d\n",i,j,s[i][j]); 18 } 19 }
2023 求平均成绩
1 #include2 3 int main(){ 4 int s[51][10]; 5 int n,m,i,j,k,flag,count; 6 double sum,c[50]; 7 while(scanf("%d %d",&n,&m)!=EOF){ 8 k=0;count=0; 9 for(i=0;i ){ 10 for(j=0;j "%d",&s[i][j]);} 11 } 12 13 for(i=0;i ){ 14 sum = 0; 15 for(j=0;j ){ 16 sum += s[i][j]; 17 } 18 if(i==n-1){printf("%.2lf\n",sum/m);} 19 else{printf("%.2lf ",sum/m);} 20 } 21 for(i=0;i ){ 22 sum = 0; 23 for(j=0;j ){ 24 sum += s[j][i]; 25 } 26 c[k] = sum/n; 27 k++; 28 if(i==m-1){printf("%.2lf\n",sum/n);} 29 else{printf("%.2lf ",sum/n);} 30 } 31 for(i=0;i ){ 32 flag = 0; 33 for(j=0;j ){ 34 if(s[i][j] ;} 35 } 36 if(flag==0){count++;} 37 } 38 printf("%d\n\n",count); 39 } 40 41 }
2024 C语言合法标识符
1 #include2 #include 3 4 int main(){ 5 char s[51]; 6 int n,len,i,flag; 7 while(scanf("%d",&n)!=EOF){ 8 getchar(); 9 while(n--){ 10 gets(s); 11 len = strlen(s); 12 if((s[0]=='_')||(s[0]>='a'&&s[0]<='z')||(s[0]>='A'&&s[0]<='Z')){ 13 flag = 0; 14 for(i=1;i ){ 15 if((s[i]=='_')||(s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z')||(s[i]>='0'&&s[i]<='9')){ 16 continue; 17 }else{flag++;break;} 18 } 19 if(flag==0){printf("yes\n");} 20 else{printf("no\n");} 21 }else{printf("no\n");} 22 23 } 24 } 25 26 }
2025 查找最大元素
1 #include2 #include <string.h> 3 4 int main(){ 5 char s[101],m; 6 int i,len; 7 while(gets(s)!=NULL){ 8 len = strlen(s); 9 m = 'a'; 10 for(i=0;i ){ 11 if(s[i]>=m){m = s[i];} 12 } 13 for(i=0;i ){ 14 printf("%c",s[i]); 15 if(s[i]==m){printf("(max)");} 16 } 17 printf("\n"); 18 } 19 }
这题有个坑,输出格式问题:
while(gets(str)!=NULL) NULL返回值对应的是char while(scanf("%d",&x)!=EOF) EOF返回值对应却是int
2026 首字母变大写
1 #include2 #include <string.h> 3 4 int main(){ 5 char s[101]; 6 int i,len; 7 while(gets(s)!=NULL){ 8 len = strlen(s); 9 s[0] -= 32; 10 for(i=1;i ){ 11 if(s[i]==' '){ 12 s[i+1] -= 32; 13 } 14 } 15 for(i=0;i ){ 16 printf("%c",s[i]); 17 } 18 printf("\n"); 19 } 20 }
2027 统计元音
1 #include2 #include <string.h> 3 4 int main(){ 5 char s[101],m; 6 int n,i,j,len,s1[10]; 7 while(scanf("%d",&n)!=EOF){ 8 getchar(); 9 for(i=0;i ){ 10 gets(s); 11 len = strlen(s); 12 s1[0]=s1[1]=s1[2]=s1[3]=s1[4]=0; 13 for(j=0;j ){ 14 if(s[j]=='a'){s1[0]++;} 15 if(s[j]=='e'){s1[1]++;} 16 if(s[j]=='i'){s1[2]++;} 17 if(s[j]=='o'){s1[3]++;} 18 if(s[j]=='u'){s1[4]++;} 19 } 20 printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d\n",s1[0],s1[1],s1[2],s1[3],s1[4]); 21 if(i!=n-1){printf("\n");} 22 23 } 24 25 } 26 }
2028 Lowest Common Multiple Plus
1 #include2 3 int gcd(int x,int y){ //求x,y的最大公约数 4 if(y==0){return x;} 5 else{return gcd(y,x%y);} 6 } 7 8 int main(){ 9 int a,b,n,i; 10 while(scanf("%d",&n)!=EOF){ 11 scanf("%d",&a); 12 for(i=1;i ){ 13 scanf("%d",&b); 14 a = a*b/gcd(a,b); 15 } 16 printf("%d\n",a); 17 } 18 }
2029 Palindromes _easy version
1 #include2 #include <string.h> 3 4 int main(){ 5 int n,i,len,flag; 6 char s[100]; 7 while(scanf("%d", &n)!=EOF){ 8 getchar(); 9 while(n--){ 10 gets(s); 11 len = strlen(s); 12 flag=0; 13 for(i=0;i ){ 14 if(s[i]!=s[len-i-1]){flag=1;break;} 15 16 } 17 if(flag==0){printf("yes\n");} 18 else{printf("no\n");} 19 } 20 } 21 }
2030 汉字统计
1 #include2 #include <string.h> 3 4 int main(){ 5 int n,i,len,flag; 6 char s[1000]; 7 while(scanf("%d", &n)!=EOF){ 8 getchar(); 9 while(n--){ 10 gets(s); 11 len = strlen(s); 12 flag = 0; 13 for(i=0;i ){ 14 if(s[i]<0){flag++;} 15 } 16 printf("%d\n",flag/2); 17 } 18 } 19 }
注:
1—— 一个汉字在字符串中是以两个负的字符形式存储,所以本题只要把字符串中负字符的个数找出来,再除以2 就OK了。 2——汉字机内码在计算机的表达方式的描述是,使用二个字节,每个字节最高位一位为1。 计算机中, 补码第一位是符号位, 1 表示为 负数,
所以 汉字机内码的每个字节表示的十进制数都是负数