如果有问题欢迎指出......本代码只在本地测试,无法提交OJ测试。难免会有问题。共同学习.......
#include<stdio.h> #include<string.h> #include<stdlib.h> int cmp(const void *a,const void *b){ return *(int *)a - *(int *)b; } int main () { int N,index,i; int Sum[1001]; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); memset(Sum,0,sizeof(Sum)); index = 0; while(scanf("%d",&N) != EOF){ if(N == 0){ //排序 qsort(Sum,index,sizeof(Sum[0]),cmp); for(i = 0;i < index;i++){ if(i == index-1){ printf("%d\n",Sum[i]); } else{ printf("%d ",Sum[i]); } } break; } //计算各位之和 while(N){ Sum[index] += N % 10; N /= 10; } index++; } return 0; }
#include<stdio.h> #include<stdlib.h> #include<limits.h> int Matrix[101][101]; typedef struct MinMax{ int x; int y; int value; }MM; int main () { int N,M,i,j; MM Min[101],Max[101]; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); while(scanf("%d %d",&N,&M) != EOF){ for(i = 0;i < N;i++){ Min[i].value = INT_MAX; for(j = 0;j < M;j++){ scanf("%d",&Matrix[i][j]); //每行的最小值 if(Matrix[i][j] < Min[i].value){ Min[i].value = Matrix[i][j]; } } } for(j = 0;j < M;j++){ Max[j].value = INT_MIN; for(i = 0;i < N;i++){ //每列的最大值 if(Max[j].value < Matrix[i][j]){ Max[j].value = Matrix[i][j]; } } } //输出马鞍点 int flag= 0; for(i = 0;i < N;i++){ for(j = 0;j < M;j++){ if(Min[i].y == Max[j].y && Min[i].x == Max[j].x && Min[i].value == Max[j].value){ flag = 1; printf("%d %d %d\n",i,j,Min[i].value); } } } //如果没有马鞍点输出no if(flag == 0){ printf("no\n"); } } return 0; }
#include<stdio.h> #include<stdlib.h> #include<limits.h> int Matrix[101][101]; int main () { int N,M,i,j,index,flag,mark; int Min; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); while(scanf("%d %d",&N,&M) != EOF){ mark = 0; //输入数据 for(i = 0;i < N;i++){ for(j = 0;j < M;j++){ scanf("%d",&Matrix[i][j]); } } for(i = 0;i < N;i++){ Min = INT_MAX; for(j = 0;j < M;j++){ //每行的最小值 if(Min > Matrix[i][j]){ Min = Matrix[i][j]; index = j; } } //在其所在的列判断他是不是最大值 flag = 0; for(j = 0;j < N;j++){ if(Min < Matrix[j][index]){ flag = 1; break; } } if(flag == 0){ printf("%d %d %d\n",i,index,Min); mark = 1; } } //如果没有马鞍点输出no if(mark == 0){ printf("no\n"); } } return 0; }
#include<stdio.h> #include<stdlib.h> #include<string.h> int main () { int i,j,len,num; char str[101]; char pre; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); while(scanf("%s",str) != EOF){ len = strlen(str); num = 0; //输出解压缩 for(i = 0;i < len;i++){ if(str[i] < '0' || str[i] > '9'){ for(j = 0;j < num-1;j++){ printf("%c",pre); } num = 0; //要输出的字符 pre = str[i]; printf("%c",str[i]); } else{ //提取数字 num = num * 10 + str[i] - '0'; } } for(i = 0;i < num - 1;i++){ printf("%c",pre); } printf("\n"); } return 0; }
测试用例:
a5b3aba13b4
输出:aaaaabbbabaaaaaaaaaaaaabbbb
bbabab3a5abb
输出:
bbababbbaaaaaabb