PAT_C语言习题
赛亚人_1
开通博客发表自己的一些编程代码以及学习的一些感受,希望各位朋友能给予我一些宝贵的建议。
展开
-
求a的连续和(15)
#include#includeint main(){ int a,n; int i; int sum; while(scanf("%d%d",&a,&n)!=EOF) { if(a>9||a8||n<1) continue; sum=0; for(i=0;i<n;i++) sum+=(n-i)*a*pow(10,i); printf("%d\n",sum);原创 2015-01-24 15:15:09 · 461 阅读 · 0 评论 -
念数字(15)
#includechar a[10][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};int output(int n,int m){ if(n>=10) output(n/10,m); if(n<m) printf("%s ",a[n%10]); if(n>=m) printf("%s\n",a[n%10]);原创 2015-01-24 15:05:14 · 475 阅读 · 0 评论 -
混合类型数据格式化输入(5)
#includeint main(){ int n; char e; double d1,d2; while(scanf("%lf%d",&d1,&n)!=EOF) { e=getchar(); while(e==' ') scanf("%c",&e); scanf("%lf",&d2); printf("%c %d %0.2lf %0.2lf\n",e,n,d原创 2015-01-24 15:38:18 · 614 阅读 · 0 评论 -
字符串逆序(15)
#include#includeint main(){ char str[81],e; int i,len; while(gets(str)!=NULL) { len=strlen(str); for(i=0;i<len/2;i++) { e=str[i]; str[i]=str[len-1-i]; str[len-i-1]=e; } puts(原创 2015-01-25 14:43:04 · 804 阅读 · 0 评论 -
字符串循环左移(20)
#include#includevoid reverse(char *s,int low,int high){ char t; while(low<high) { t=*(s+low); *(s+low)=*(s+high); *(s+high)=t; low++; high--; }}int main() { char str[101]; int n,原创 2015-01-25 16:04:59 · 652 阅读 · 0 评论 -
换个格式输出整数 (15)
#includeint main(){ int n,i; int a,b,c; while(scanf("%d",&n)!=EOF) { if(n>=1000||n<1) continue; a=n/100; b=n/10%10; c=n%10; for(i=0;i<a;i++) printf("B"); for(i=0;i<b;i++) printf("S")原创 2015-01-25 09:45:24 · 394 阅读 · 0 评论 -
平面向量加法(10)
#includetypedef struct X_L{ double x; double y;}X_L;int main(){ X_L v1,v2; double a,b; while(scanf("%lf%lf%lf%lf",&v1.x,&v1.y,&v2.x,&v2.y)!=EOF) { a=v1.x+v2.x;b=v1.y+v2.y; if((v1.x+v2.x原创 2015-01-25 16:29:07 · 513 阅读 · 0 评论 -
猜数字游戏(15)
#includeint main(){ int m,n,i,c; while(scanf("%d%d",&m,&n)!=EOF) { if(m100||n>100) continue; for(i=1;i<=n;i++) { scanf("%d",&c); if(c>m) printf("Too big\n"); if(c==m) { if(i原创 2015-01-24 12:11:00 · 515 阅读 · 0 评论 -
求序列前N项和(15)
#includeint main(){ int n,i; double a,b,t; double sum; while(scanf("%d",&n)!=EOF) { if(n<1) continue; a=2.0; b=1.0; sum=0.0; for(i=0;i<n;i++) { sum+=a/b; t=a; a=a+b; b=t;原创 2015-01-24 12:11:55 · 559 阅读 · 0 评论 -
写出这个数 (20)
#include#define N 101char s[10][5]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};int main(){ char str[N]; int i,n; int a,b,c; while(~scanf("%s",str)) { n=0,i=0; while(str[i]!='原创 2015-01-24 23:56:06 · 400 阅读 · 0 评论 -
08-1. 求一批整数中出现最多的个位数字(20)
#include#includeint main(){ int n,i,max; int *a; int b[10]; while(~scanf("%d",&n)) { for(i=0;i<10;i++) b[i]=0; a=(int *)malloc(n*sizeof(int)); for(i=0;i<n;i++){ scanf("%d",&a[i]);原创 2015-01-25 11:38:20 · 817 阅读 · 0 评论 -
求矩阵的局部极大值(15)
#include#includeint main(){ int m,n,i,j; int count; int **a; while(~scanf("%d%d",&m,&n)) { if(m20||n>20) continue; count=0; a=(int **)malloc(m*sizeof(int *)); for(i=0;i<n;i++) a[i]=(in原创 2015-01-25 12:10:32 · 706 阅读 · 0 评论 -
在字符串中查找指定字符(15)
#includeint main(){ char e,str[80]; int i; while(gets(str)!=NULL) { e=getchar(); if(e=='\n') scanf("%c",&e); i=0; while(str[i]!='\0'){ if(str[i]==e) break; i++; } if(str[i]=='\原创 2015-01-25 13:39:36 · 874 阅读 · 0 评论 -
单词长度(15)
#include#define N 100int main(){ int i,n,flag,flag2; char str[N]; while(gets(str)!=NULL) { n=0; flag=0;flag2=0; for(i=0;str[i]!='.';i++) { if(str[i]==' '&&flag==1){ if(n>0) printf(原创 2015-01-24 23:31:00 · 412 阅读 · 0 评论 -
A+B和C (15)
#include#includeint main(){ int n,i; long a,b,c; int *d; scanf("%d",&n); d=(int *)malloc(n*sizeof(int)); for(i=0;i<n;i++) { scanf("%ld%ld%ld",&a,&b,&c); d[i]=(a+b>c)?1:0; } for(i=0;i<n;原创 2015-01-25 10:22:24 · 401 阅读 · 0 评论 -
查找整数(10)
#include#includeint main(){ int n,x,i; int *a; while(~scanf("%d%d",&n,&x)) { if(n>20) continue; a=(int *)malloc(n*sizeof(int)); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) i原创 2015-01-25 11:16:02 · 390 阅读 · 0 评论 -
组个最小数 (20)
#includeint main(){ int a[10]; int i,j; while(~scanf("%d",&a[0])) { for(i=1;i<10;i++) scanf("%d",&a[i]); for(i=1;i<10;i++) if(a[i]>0){ printf("%d",i); a[i]--; break; } fo原创 2015-01-25 13:07:29 · 472 阅读 · 0 评论 -
说反话 (20)
#includevoid output(char *str){ int i=0; int j; while(str[i]!=' '&&str[i]!='\0') i++; if(str[i]==' ') output(str+i+1); if(str[i]==' ') printf(" "); for(j=0;j<i;j++) printf("%c",str[j]);}int原创 2015-01-25 13:26:07 · 432 阅读 · 0 评论 -
数素数 (20)
#include#includeint isprime(int n){ if(n==2||n==3) return 1; if(n%2==0) return 0; int i; for(i=3;i<=sqrt(n);i++) if(n%i==0) return 0; return 1;}int main(){ int m,n,i; int count,flag; w原创 2015-01-25 11:05:05 · 370 阅读 · 0 评论 -
约分最简分式(15)
#includeint main(){ int n,m; int a,b,r; char e; while(scanf("%d",&n)!=EOF) { scanf("%c%d",&e,&m); if(n<1||m<1||e!='/') continue; a=(m>n)?m:n; b=(m<n)?m:n; r=a%b; while(r) { a=b原创 2015-01-24 12:13:10 · 717 阅读 · 0 评论 -
简单计算器(20)
#includeint main(){ int a,b; int flag; char ch;// while(scanf("%d",&a)!=EOF)// { scanf("%d",&a); scanf("%c",&ch); flag=0; while(ch!='=') { scanf("%d",&b); switch(ch) { ca原创 2015-01-24 16:39:20 · 460 阅读 · 0 评论 -
字符串字母大小写转换(10)
#includeint main(){ char str[41]; int i; while(gets(str)!=NULL) { i=0; while(str[i]!='#') { if(str[i]>='a'&&str[i]<='z') str[i]-='a'-'A'; else if(str[i]>='A'&&str[i]<='Z') str[i]+='a原创 2015-01-24 16:58:34 · 983 阅读 · 0 评论 -
求矩阵的局部极大值(15)
#include#includeint main(){ int m,n,i,j; int count; int **a; while(~scanf("%d%d",&m,&n)) { if(m20||n>20) continue; count=0; a=(int **)malloc(m*sizeof(int *)); for(i=0;i<n;i++) a[i]=(in原创 2015-01-25 11:59:45 · 6363 阅读 · 0 评论 -
水仙花数(20)
#include#includeint main(){ int i,n,m,t,c,j; while(scanf("%d",&n)!=EOF) { if(n7) continue; m=pow(10,n-1); for(i=m;i<10*m;i++) { t=i; c=0; for(j=0;j<n;j++) { c+=pow(t%10,n);原创 2015-01-21 16:04:49 · 356 阅读 · 0 评论 -
三天打鱼两天晒网(15)
#includeint main(){ int n; while(scanf("%d",&n)!=EOF) { if(n1000) continue; else if(n%5==1||n%5==2||n%5==3) printf("Fishing in day %d\n",n); else printf("Drying in day %d\n",n); } return原创 2015-01-21 14:07:50 · 969 阅读 · 0 评论 -
整数四则运算(10)
#includeint main(){ int A,B; while(scanf("%d%d",&A,&B)!=EOF) { printf("%d + %d = %d\n",A,B,A+B); printf("%d - %d = %d\n",A,B,A-B); printf("%d * %d = %d\n",A,B,A*B); printf("%d / %d = %d\n原创 2015-01-21 13:19:16 · 1286 阅读 · 1 评论 -
成绩转换(15)
#includeint main(){ int n; char ch; while(scanf("%d",&n)!=EOF) { if(n>100||n<0) continue; if(n>=90) ch='A'; else if(n>=80) ch='B'; else if(n>=70) ch='C'; else if(n>=60) ch='D'; else原创 2015-01-21 14:36:58 · 470 阅读 · 0 评论 -
厘米换算英尺英寸(15)
#include int main() { int n; int a,b; float t; while(scanf("%d",&n)!=EOF) { t=(float)n/30.48; a=(int)t; t=t-a; b=(int)(t*12); printf("%d %d\n",a,b); } return 0;}原创 2015-01-21 13:19:55 · 597 阅读 · 0 评论 -
然后是几点(15)
#includeint main(){ int a,b; int m,n,c; while(scanf("%d%d",&a,&b)!=EOF) { m=a/100; n=a%100; c=m*60+n+b; m=c/60; n=c%60; if(m>=24||m<0) continue; printf("%d\n",m*100+n); }}原创 2015-01-21 13:20:56 · 529 阅读 · 0 评论 -
逆序的三位数(10)
#includeint main(){ int n; int a,b,c; while(scanf("%d",&n)!=EOF) { if(n=1000)continue; c=n%10; b=n/10%10; a=n/100; n=a+b*10+c*100; printf("%d\n",n); }}原创 2015-01-21 13:43:01 · 375 阅读 · 0 评论 -
BCD解密(10)
#includeint main(){ int n; int a,b; while(scanf("%d",&n)!=EOF) { if(n153||n%16>9) continue; a=n/16; b=n%16; printf("%d\n",a*10+b); } return 0;}原创 2015-01-21 13:55:33 · 708 阅读 · 0 评论 -
超速判断(10)
#includeint main(){ int n; while(scanf("%d",&n)!=EOF) { if(n500) continue; else if(n<=60) printf("Speed: %d - OK\n",n); else printf("Speed: %d - Speeding\n",n); } return 0;}原创 2015-01-21 14:01:28 · 579 阅读 · 0 评论 -
12-24小时制(15)
#includeint main(){ int n,m; char ch; while(scanf("%d%c%d",&n,&ch,&m)!=EOF) { if(n=24||m=60||ch!=':') continue; if(n<12) printf("%d%c%d AM\n",n,ch,m); if(n==12) printf("%d%c%d PM\n",n,ch,m原创 2015-01-21 14:31:03 · 487 阅读 · 0 评论 -
求符合给定条件的整数集(15)
#includeint main(){ int n; int i,j,k; while(scanf("%d",&n)!=EOF) { int m=1; if(n>6||n<1) continue; for(i=n;i<n+4;i++) for(j=n;j<n+4;j++) for(k=n;k<n+4;k++) if(i!=j&&j!=k&&i!=k)原创 2015-01-21 14:49:24 · 477 阅读 · 0 评论 -
统计素数并求和(20)
#include#includeint isprime(int n){ if(n==1) return 0; if(n==2||n==3) return 1; int i; for(i=2;i<=sqrt(n);i++) if(n%i==0) return 0; return 1;}int main(){ int m,n,i,count,sum; while(scan原创 2015-01-23 23:50:32 · 776 阅读 · 0 评论 -
水仙花数——升级版
#include#include#define M 7 int sum[10][M];void pow_1(int m){ int i,j,c; for(i=0;i<10;i++) for(j=0;j<M;j++) sum[i][j]=0; for(i=0;i<10;i++) sum[i][M-1]=pow(i,m); for(i=2;i<10;i++) { c原创 2015-01-22 22:32:26 · 473 阅读 · 0 评论 -
打印九九口诀表(15)
#includeint main(){ int n; int i,j; while(scanf("%d",&n)!=EOF) { if(n9) continue; for(i=1;i<=n;i++) { for(j=1;j<=i;j++) printf("%d*%d=%-4d",j,i,i*j); printf("\n"); } } return原创 2015-01-23 23:39:00 · 479 阅读 · 0 评论 -
删除字符串中的子串(20)
#include#includeint issubstring(char *s1,char *s2){ int i=0,j; int len2=strlen(s2); while(s1[i+len2-1]!='\0') { for(j=0;s2[j]!='\0';j++) if(s1[i+j]!=s2[j]) break; if(s2[j]=='\0') return原创 2015-01-25 14:35:32 · 536 阅读 · 0 评论