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