acm试题c语言版
鄭輕acm試題(部分)代碼
雞兔同籠 #include<stdio.h>int main() { int m,n,s,d;scanf("%d %d",&m,&n);s=(4*m-n)/2;d=m-s;printf("%d %d\n",s,d);return 0; } 等差數列 #include<stdio.h>int main() { int m,n,s,f,d;scanf("%d %d %d",&m,&n,&s);f=(n-m)/s+1;d=(n+m)*f/2;printf("%d\n",d);return 0; } 1008 貨幣兌換 #include<stdio.h> int main() { double m,n;scanf("%lf",&m);n=6.5573*m;printf("%.2lf\n",n);} 1011圓柱表面積 #include<stdio.h> #define PI 3.14159 int main() { double m,h,n,d,s;scanf("%lf %lf",&m,&h);n=2*PI*m;d=PI*m*m;s=n*h+2*d;printf("%.2lf\n",s);return 0; } 1013 2點間距離 #include<stdio.h> #include<math.h> int main() { double a,b,c,d,s;scanf("%lf %lf %lf %lf",&a,&b,&c,&d);s=(c-a)*(c-a)+(d-b)*(d-b);printf("%.2lf\n",sqrt(s));return 0; } /................/ 1014 任意三角形的面積 #include<stdio.h> #include<math.h> int main() { double a,b,c,p,s;scanf("%lf %lf %lf",&a,&b,&c);p=(a+b+c)/2;s=p*(p-a)*(p-b)*(p-c);printf("%.2lf\n",sqrt(s));return 0; } 1015 #include<stdio.h> #include<math.h> int main() { double a,b,c,x1,x2;scanf("%lf %lf %lf",&a,&b,&c);x1=(-b+sqrt(b*b-4*a*c))/(2*a);x2=(-b-sqrt(b*b-4*a*c))/(2*a);printf("%7.2lf%7.2lf\n",x1,x2);return 0; } 1016銀行利率求本息和。 #include<stdio.h> #include<math.h> int main(){ int n;double a,c;scanf("%d %lf",&n,&a);c=a*pow(1+0.0225,n);printf("%.6lf\n",c);return 0; } 1017奇偶判斷 #include<stdio.h> int main() { int n;scanf("%d",&n);if(n%2==0){printf("even\n");}else{printf("odd\n");}return 0; } 1019公園售票 #include<stdio.h> int main() { double n;scanf("%lf",&n);if(n<30){printf("%.2lf\n",50*n);}else{printf("%.2lf\n",48*n);}return 0; } 1020排序 #include<stdio.h> int main() { int a,b;scanf("%d %d",&a,&b);if(a<b){printf("%d %d\n",a,b);}else{printf("%d %d\n",b,a);}return 0; } 1021三個數求最大值 #include<stdio.h> int main() { int a,b,c,s,i;scanf("%d %d %d",&a,&b,&c);int k[3]={a,b,c};s=a;for(i=0;i<3;i++){if(s<=k[i]){s=k[i];}}printf("%d\n",s);return 0; } 1022三個數排序 #include<stdio.h> int main() { int x,y,z,i,j,s;scanf("%d %d %d",&x,&y,&z);int k[3]={x,y,z};for(i=0;i<3;i++){for(j=i+1;j<3;j++){if(k[i]<k[j]){s=k[i];k[i]=k[j];k[j]=s;}}}for(i=0;i<3;i++){printf("%d",k[i]);printf(" ");}return 0; } 1023大小寫轉換 #include<stdio.h> int main() { char a; scanf("%c",&a); if(a>='a'&&a<='z') a=a-32;elsea=a; printf("%c\n",a);return 0; } 1024計算字母序號 #include<stdio.h> int main() { char sum; scanf("%c",&sum); if(sum>='a'&&sum<='z') sum=sum-'a'+1;elsesum=sum-'A'+1; printf("%d\n",sum);return 0; } 1027判斷水仙花數 #include<stdio.h> int main() {int s,a,b,c,d;scanf("%d",&s);a=s/100;b=s%100/10;c=s%10;d=a*a*a+b*b*b+c*c*c;if(s==d)printf("yes\n");elseprintf("no\n");return 0; } 1028水仙花數 #include<stdio.h> int main() {int s;scanf("%d",&s);if(s%4==0&&s%100!=0||s%400==0)printf("Yes\n");elseprintf("No\n");return 0; } 1029判定為三角形 #include<stdio.h> int main() {int a,b,c;scanf("%d %d %d",&a,&b,&c);if(a+b>c&&a+c>b&&b+c>a)printf("Yes\n");elseprintf("No\n");return 0; } 1030判定為直角三角形 #include<stdio.h> int main() {int a,b,c,x,y,z,i,j,s;scanf("%d %d %d",&a,&b,&c);int k[3]={a,b,c};for(i=0;i<3;i++){for(j=i+1;j<3;j++){if(k[i]<k[j]){s=k[i];k[i]=k[j];k[j]=s;}}}x=k[0];y=k[1];z=k[2];if(a+b>c&&a+c>b&&b+c>a&&x*x==y*y+z*z)printf("yes\n");elseprintf("no\n");return 0; } 1032算工資 #include<stdio.h> int main() {double a,b;scanf("%lf",&a);if(a<=10000){b=0.05*a;}else { if(a<=50000){b=0.05*10000+(a-10000)*0.03;}else{b=0.05*10000+40000*0.03+0.02*(a-50000);}}printf("%.2lf\n",1500+b);return 0; } 1033 五級制成績 #include<stdio.h> int main() {int a;char b;scanf("%d",&a);if(a>=90){b='A';}else if(a>=80){b='B';}else if(a>=70){b='C';} else if(a>=60) {b='D'; } else {b='E'; }printf("%c\n",b);return 0; } 1034 夏季促銷 #include<stdio.h> int main() {double a,b;scanf("%lf",&a);if(a<500){b=a;}else if(a<1000){b=0.95*a;}else if(a<3000){b=0.9*a;} else if(a<5000) {b=0.85*a; } else {b=0.8*a; }printf("%.2lf\n",b);return 0; }?
轉載于:https://www.cnblogs.com/xiaogou/p/5055090.html
總結
- 上一篇: Incorrect string val
- 下一篇: 创建DataTable并把列默认值