欢迎来到天天文库
浏览记录
ID:2158993
大小:28.43 KB
页数:7页
时间:2017-11-14
《湘潭大学c语言撑血设计实践》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.john的农场#include#defineN20intmain(){inta[N+1][N+1];intn,m,i,j,min,k,l,q,sum;intw,minx,max;scanf("%d",&n);while(n--){intb[N+1]={0};scanf("%d",&m);for(i=1;i<=m;i++)for(j=1;j<=m;j++)scanf("%d",&a[i][j]);sum=0;q=m-1;w=1;while(q){min=99999;for(i=1;i2、a[i][j]==0)continue;else{if(min>a[i][j]){min=a[i][j];k=i;l=j;}}}if(b[k]==0&&b[l]==0){b[k]=w;b[l]=w;w++;sum=sum+min;a[k][l]=0;q--;}elseif(b[k]==03、4、b[l]==0){if(b[k]==0)b[k]=b[l];if(b[l]==0)b[l]=b[k];sum=sum+min;a[k][l]=0;q--;}elseif(b[k]==b[l])a[k][l]=0;else{minx=b[k];max=b[k];if(b[l]<5、b[k])minx=b[l];elsemax=b[l];for(i=1;i<=m;i++)if(b[i]==max)b[i]=minx;sum=sum+min;a[k][l]=0;q--;}}printf("%d",sum);}return0;}2.xtu方阵#includeintmain(){intn,i,j,s=0;while(1){scanf("%d",&n);if(n==0)break;s++;printf("Case%d:",s);for(i=0;i<3*n;i++){for(j=0;j6、);}printf("");}printf("");}return0;}3.z字型#include#include#includeintmain(){chara[10][10],b[100];inti,j,l,n,k;doubles;while(scanf("%s",b)!=-1){s=strlen(b);s=sqrt(s);n=int(s);l=0;for(i=0;i7、i+1;j++)a[j][i-j]=b[l++];}for(i=n-2,k=n;i>=0;i--,k++){if(i%2==0)for(j=0;jintmain(){intk,i,j,8、x,y;chara[5],b[5];while(1){scanf("%s",a);if(a[0]=='0')break;scanf("%d",&k);while(k--){scanf("%s",b);x=0;y=0;for(i=0;i<4;i++)if(a[i]==b[i])x++;for(i=0;i<4;i++){for(j=0;j<4;j++)if(a[i]==b[j])y++;}if(k!=0)printf("%dA%dB",x,y-x);elseprintf("%dA%dB",x,y-x);}}return0;}5.成对的字符串#include9、dio.h>#defineN1000intmain(){chara[N+1];ints,x,n,i=1;char*p,*q,m;scanf("%d",&s);while(s){n=1;if((s--)==0)break;scanf("%s",a);p=a;while(*p){if(*p=='*'){p++;continue;}q=p;m=*q;i=1;x=0;while(*q&&(*q)!='*'){q++;if(m==*q){i++;if(x==0)*q='*';x++;}}if(i%2!=0){n=0;break;}p++;}if(n==0)printf("10、No");elsep
2、a[i][j]==0)continue;else{if(min>a[i][j]){min=a[i][j];k=i;l=j;}}}if(b[k]==0&&b[l]==0){b[k]=w;b[l]=w;w++;sum=sum+min;a[k][l]=0;q--;}elseif(b[k]==0
3、
4、b[l]==0){if(b[k]==0)b[k]=b[l];if(b[l]==0)b[l]=b[k];sum=sum+min;a[k][l]=0;q--;}elseif(b[k]==b[l])a[k][l]=0;else{minx=b[k];max=b[k];if(b[l]<
5、b[k])minx=b[l];elsemax=b[l];for(i=1;i<=m;i++)if(b[i]==max)b[i]=minx;sum=sum+min;a[k][l]=0;q--;}}printf("%d",sum);}return0;}2.xtu方阵#includeintmain(){intn,i,j,s=0;while(1){scanf("%d",&n);if(n==0)break;s++;printf("Case%d:",s);for(i=0;i<3*n;i++){for(j=0;j6、);}printf("");}printf("");}return0;}3.z字型#include#include#includeintmain(){chara[10][10],b[100];inti,j,l,n,k;doubles;while(scanf("%s",b)!=-1){s=strlen(b);s=sqrt(s);n=int(s);l=0;for(i=0;i7、i+1;j++)a[j][i-j]=b[l++];}for(i=n-2,k=n;i>=0;i--,k++){if(i%2==0)for(j=0;jintmain(){intk,i,j,8、x,y;chara[5],b[5];while(1){scanf("%s",a);if(a[0]=='0')break;scanf("%d",&k);while(k--){scanf("%s",b);x=0;y=0;for(i=0;i<4;i++)if(a[i]==b[i])x++;for(i=0;i<4;i++){for(j=0;j<4;j++)if(a[i]==b[j])y++;}if(k!=0)printf("%dA%dB",x,y-x);elseprintf("%dA%dB",x,y-x);}}return0;}5.成对的字符串#include9、dio.h>#defineN1000intmain(){chara[N+1];ints,x,n,i=1;char*p,*q,m;scanf("%d",&s);while(s){n=1;if((s--)==0)break;scanf("%s",a);p=a;while(*p){if(*p=='*'){p++;continue;}q=p;m=*q;i=1;x=0;while(*q&&(*q)!='*'){q++;if(m==*q){i++;if(x==0)*q='*';x++;}}if(i%2!=0){n=0;break;}p++;}if(n==0)printf("10、No");elsep
6、);}printf("");}printf("");}return0;}3.z字型#include#include#includeintmain(){chara[10][10],b[100];inti,j,l,n,k;doubles;while(scanf("%s",b)!=-1){s=strlen(b);s=sqrt(s);n=int(s);l=0;for(i=0;i7、i+1;j++)a[j][i-j]=b[l++];}for(i=n-2,k=n;i>=0;i--,k++){if(i%2==0)for(j=0;jintmain(){intk,i,j,8、x,y;chara[5],b[5];while(1){scanf("%s",a);if(a[0]=='0')break;scanf("%d",&k);while(k--){scanf("%s",b);x=0;y=0;for(i=0;i<4;i++)if(a[i]==b[i])x++;for(i=0;i<4;i++){for(j=0;j<4;j++)if(a[i]==b[j])y++;}if(k!=0)printf("%dA%dB",x,y-x);elseprintf("%dA%dB",x,y-x);}}return0;}5.成对的字符串#include9、dio.h>#defineN1000intmain(){chara[N+1];ints,x,n,i=1;char*p,*q,m;scanf("%d",&s);while(s){n=1;if((s--)==0)break;scanf("%s",a);p=a;while(*p){if(*p=='*'){p++;continue;}q=p;m=*q;i=1;x=0;while(*q&&(*q)!='*'){q++;if(m==*q){i++;if(x==0)*q='*';x++;}}if(i%2!=0){n=0;break;}p++;}if(n==0)printf("10、No");elsep
7、i+1;j++)a[j][i-j]=b[l++];}for(i=n-2,k=n;i>=0;i--,k++){if(i%2==0)for(j=0;jintmain(){intk,i,j,
8、x,y;chara[5],b[5];while(1){scanf("%s",a);if(a[0]=='0')break;scanf("%d",&k);while(k--){scanf("%s",b);x=0;y=0;for(i=0;i<4;i++)if(a[i]==b[i])x++;for(i=0;i<4;i++){for(j=0;j<4;j++)if(a[i]==b[j])y++;}if(k!=0)printf("%dA%dB",x,y-x);elseprintf("%dA%dB",x,y-x);}}return0;}5.成对的字符串#include9、dio.h>#defineN1000intmain(){chara[N+1];ints,x,n,i=1;char*p,*q,m;scanf("%d",&s);while(s){n=1;if((s--)==0)break;scanf("%s",a);p=a;while(*p){if(*p=='*'){p++;continue;}q=p;m=*q;i=1;x=0;while(*q&&(*q)!='*'){q++;if(m==*q){i++;if(x==0)*q='*';x++;}}if(i%2!=0){n=0;break;}p++;}if(n==0)printf("10、No");elsep
9、dio.h>#defineN1000intmain(){chara[N+1];ints,x,n,i=1;char*p,*q,m;scanf("%d",&s);while(s){n=1;if((s--)==0)break;scanf("%s",a);p=a;while(*p){if(*p=='*'){p++;continue;}q=p;m=*q;i=1;x=0;while(*q&&(*q)!='*'){q++;if(m==*q){i++;if(x==0)*q='*';x++;}}if(i%2!=0){n=0;break;}p++;}if(n==0)printf("
10、No");elsep
此文档下载收益归作者所有