文件后缀“.cpp” 提交选择“G++”编译器
8
1 #include<stdio.h> 2 int num[100]; 3 int main() 4 { 5 int x; 6 int cnt = 0; 7 scanf("%d", &x); 8 while(x) { 9 num[++cnt] = x % 10; 10 x = x / 10; 11 } 12 if(!cnt) printf("0 "); 13 else { 14 for(int i = cnt; i>=1; i--) 15 printf("%d ", num[i]); 16 } 17 return 0; 18 }
9
1 #include<stdio.h> 2 int main() 3 { 4 int x; 5 scanf("%d", &x); 6 printf("%c ", x); 7 return 0; 8 }
10
#include<stdio.h> int main() { int x; scanf("%d",&x); printf("x=%d,x=%o,x=%x ", x, x, x); return 0; } // -1 // x=-1,x=37777777777, x=ffffffff
11
#include<stdio.h> int main() { int x, y, ans; char op; scanf("%d %c %d", &x, &op, &y); if(op=='+') ans = x + y; else if(op=='-') ans = x - y; else if(op=='/') ans = x / y; else ans = x % y; printf("%d ", ans); return 0; }
12
#include<stdio.h> int fun(int x, char op, int y) { int ans; if(op=='+') ans = x + y; else if(op=='-') ans = x - y; else if(op=='/') ans = x / y; else ans = x % y; return ans; } int main() { int x, y; char op; scanf("%d %d %c",&x, &y, &op); if(op=='/' && y==0) printf("Go to hell! "); printf("%d ", fun(x, op, y)); return 0; }
13
#include<stdio.h> int main() { int op; double d, ans; scanf("%d %lf", &op, &d); if(op==1) { ans = (d - 32) * 5 / 9; printf("The Centigrade is %.2lf ", ans); } else { ans = (d * 9 / 5) + 32; printf("The Fahrenheit is %.2lf ", ans); } return 0; }
16
#include<stdio.h> int main() { char op; op = getchar(); if(op>='a' && op<='z') op = op - 'a' + 'A'; else if(op>='A' && op<='Z') op = op - 'A' + 'a'; printf("%c ", op); return 0; }
19
#include<stdio.h> #include<math.h> int main() { int a, b, c; double x1, x2; scanf("%d %d %d", &a, &b, &c); if(a==0&&b==0) printf("Input error! "); else if(a==0){ x1 = - double(b) / c; printf("x=%.6f ", x1); } else { double t = b * b - 4 * a * c; if(t==0) printf("x1=x2=%.6f ",-double(b)/(2*a)); else if(t>0){ x1 = (-b + sqrt(t)) / (2 * a); x2 = (-b - sqrt(t)) / (2 * a); printf("x1=%.6f x2=%.6f ",x1, x2); } else { x1 = -double(b) / (2 * a); x2 = sqrt(-t) / (2 * a); printf("x1=%.6f%+.6fi ", x1, x2); printf("x2=%.6f%+.6fi ", x1, -x2); } } return 0; }
20
#include<stdio.h> #include<math.h> int main() { int x, y; while(scanf("%d %d", &x, &y)!=EOF) { // 分针走的时候 时针也走 double x_pos = (x%12) * 5 + double(y) / 60.0 * 5; // 把整个表分成60份: (x%12) * 5 -- 时针本来的位置; double(y) / 60.0 * 5 -- 因为分针,时针走的位置 double ans = fabs(x_pos - y) < 30.0 ? fabs(x_pos - y) : 60.0 - fabs(x_pos - y); // 求最小夹角 printf("At %02d:%02d the angle is %.1lf degrees. ", x, y, ans * 6.0); // ans * 6.0 一份是6度 } return 0; }
38
#include <stdio.h> #include <math.h> #include <string.h> char s[100]; int n; int get_point(char* s) { int len = strlen(s); for(int i=0; i < len; i++) if(s[i] == '.') return i; // 整数末尾添加. s[len] = '.'; return len; } main() { char op; scanf("%s %c %d", s, &op, &n); int point = get_point(s); int num = fabs(n); int i; for(i = 0; i<num; i++) { if(n>0) { s[point] = s[point+1]; if(s[point] == '