西工大C语言POJ作业(共13页).doc
精选优质文档-倾情为你奉上T051.合并字符串#include <stdio.h>#include <stdlib.h>#include <string.h>int main() char a200,b100; gets(a); gets(b); strcat(a,b); puts(a); return 0;T052.字符串排序#include <stdio.h>#include <string.h>void sort(char s1011) int i,j; char t11; for(i=0;i<9;i+) for(j=0;j<9-i;j+) if(strcmp(sj,sj+1)>0) strcpy(t,sj+1); strcpy(sj+1,sj); strcpy(sj,t); int main() char a1011,i; for(i=0;i<10;i+) scanf("%s",ai); sort(a); for(i=0;i<10;i+) printf("%s ",ai); printf("n"); return 0;T053.特殊要求字符串#include <stdio.h>#include <string.h>int main() char s100,a100,t; int len,l,i,j; gets(s); len=strlen(s); l=len/2; for(i=0;i<l;i+) for(j=0;j<l-1-i;j+) if(sj<sj+1) t=sj+1; sj+1=sj; sj=t; for(i=0;i<l;i+) ai=si; for(i=0;i<l;i+) for(j=l+len%2;j<len-i-1;j+) if(sj>sj+1) t=sj+1; sj+1=sj; sj=t; for(i=0;i<l;i+) si=si+l+len%2; sl+i+len%2=ai; puts(s); return 0;T054.统计字母间隔数字的个数并逐一输出#include <stdio.h>int main() char s500,*p; int a100=0,i=0,j; gets(s); for(p=s;*p!='0'p+) if(*p>='0'&&*p<='9') for(;*p!='0'&&*p>='0'&&*p<='9'p+) ai=ai*10+(*p-'0'); i+; printf("%dn",i); for(j=0;j<i;j+) printf("%d ",aj); printf("n"); return 0;T055.Music Composer#include <stdio.h>#include <string.h>int main() char s200; gets(s); if(s0='A'&&s1='#')s0='B's1='b'printf("%sn",s); else if(s0='A'&&s1='b')s0='G's1='#'printf("%sn",s); else if(s0='B'&&s1='b')s0='A's1='#'printf("%sn",s); else if(s0='C'&&s1='#')s0='D's1='b'printf("%sn",s); else if(s0='D'&&s1='b')s0='C's1='#'printf("%sn",s); else if(s0='D'&&s1='#')s0='E's1='b'printf("%sn",s); else if(s0='E'&&s1='b')s0='D's1='#'printf("%sn",s); else if(s0='F'&&s1='#')s0='G's1='b'printf("%sn",s); else if(s0='G'&&s1='b')s0='F's1='#'printf("%sn",s); else if(s0='G'&&s1='#')s0='A's1='b'printf("%sn",s); else printf("UNIQUEn"); return 0;T056.字符串复制(1)#include <stdio.h>void copy(char s,char a,int m) int i=0; for(i=m,m=0;si!='0'i+,m+) am=si; am='0'int main() char s101,a100; int m,i; gets(s); scanf("%d",&m); copy(s,a,m); puts(a); return 0; (2)#include<stdio.h>int main()char t100,s100;int m,count,i;char *p; /*p要和t的类型相同,否则p的步长是int的长度,p每次+都会偏移sizeof(int)个字节,而不是sizeof(char)*/i=0;count=0;p=&t0; /*p和t的类型相同,看样子你用的是比较老的C编译器,如果用目前的C+编译器,那么这一句的问题编译时刻就可以发出错误信息,编译都不能通过*/printf("Input a string:");gets(t);printf("Input an integer:");scanf("%d",&m);while(count<m)p+;count+;while(*p!='0')si=*p;p+;i+;si='0'puts(s);return 0;T057.字符串比较#include <stdio.h>int stringcompare(char s1,char s2) for(;*s1=*s2;s1+,s2+) if(*s1='0') return 0; return *s1-*s2;int main() char s1100,s2100; int d; gets(s1),gets(s2); d=stringcompare(s1,s2); printf("%dn",d); return 0;T058.删除字符#include <stdio.h>void deletechar(char s,char c) int i,j; for(i=j=0;si!='0'i+) if(si!=c) sj+=si; sj='0' int main() char s100,c; gets(s); scanf("%c",&c); deletechar(s,c); puts(s); return 0; T059.字符串左中右#include<stdio.h>#include<string.h>void Left(char src,int n,char dest)char *p;int i;p=src;for(i=0;i<n;i+)desti=*p+;desti='0'void Right(char src,int n,char dest)int i,len;char *p;len=strlen(src);p=&srclen-n;for(i=0;i<n;i+)desti=*p+;desti='0'void Mid(char src,int loc,int n,char dest)int i;char *p;p=&srcloc;for(i=0;i<n;i+)desti=*p+;desti='0'int main()char str20='0',strL20='0',strR20='0' ,strM20='0'int n,loc;gets(str);scanf("%d%d",&n,&loc);Left(str,n,strL);printf("%sn",strL);Right(str,n,strR);printf("%sn",strR);Mid(str,loc,n,strM);printf("%sn",strM);return 0;T060.Coin test#include <stdio.h>#include <string.h>#include <math.h>int gcd(int a,int b) if(a=0) return b; else if(b=0) return a; else int i=a>b?b:a; while(a%i!=0|b%i!=0) i-; return i; int main()char a1000;int c=0,b=0,i,m;gets(a);m=strlen(a);for(i=0;i<m;i+)if(ai='S')printf("WAn");break;if(ai='U')c+;if(ai='D')b+;if(c+b!=m) return 0;elseif(fabs(double)c)/m-0.5)>0.003) printf("Failn");elseprintf("%d/%dn",c/gcd(c,m),m/gcd(c,m);return 0;专心-专注-专业