文件后缀“.cpp” 提交选择“G++”编译器
8
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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\n"); 13 else { 14 for(int i = cnt; i>=1; i--) 15 printf("%d\n", num[i]); 16 } 17 return 0; 18 }
9
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 int main() 3 { 4 int x; 5 scanf("%d", &x); 6 printf("%c\n", x); 7 return 0; 8 }
10
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> int main() { int x; scanf("%d",&x); printf("x=%d,x=%o,x=%x\n", x, x, x); return 0; } // -1 // x=-1,x=37777777777, x=ffffffff
11
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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\n", ans); return 0; }
12
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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!\n"); printf("%d\n", fun(x, op, y)); return 0; }
13
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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\n", ans); } else { ans = (d * 9 / 5) + 32; printf("The Fahrenheit is %.2lf\n", ans); } return 0; }
16
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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\n", op); return 0; }
19
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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!\n"); else if(a==0){ x1 = - double(b) / c; printf("x=%.6f\n", x1); } else { double t = b * b - 4 * a * c; if(t==0) printf("x1=x2=%.6f\n",-double(b)/(2*a)); else if(t>0){ x1 = (-b + sqrt(t)) / (2 * a); x2 = (-b - sqrt(t)) / (2 * a); printf("x1=%.6f\nx2=%.6f\n",x1, x2); } else { x1 = -double(b) / (2 * a); x2 = sqrt(-t) / (2 * a); printf("x1=%.6f%+.6fi\n", x1, x2); printf("x2=%.6f%+.6fi\n", x1, -x2); } } return 0; }
20
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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.\n", x, y, ans * 6.0); // ans * 6.0 一份是6度 } return 0; }
38
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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] == '\0') s[point] = '0'; s[point+1] = '.'; point += 1; } else{ s[point] = s[point-1]; s[point-1] = '.'; if(point-1==0) { char s0[100] = "0"; strcat(s0, s); strcpy(s, s0); } else point -= 1; } } for(int i=point+1; i<=point+8; i++) if(s[i]=='\0') s[i] = '0'; s[point+9] = '\0'; printf("%s\n", s); return 0; }
40
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> using namespace std; int a[100], b[100]; char c1[100], c2[100]; int fun(char* c, int* a, int n) { int num = 2; for(int i=0; i<n; i++) { if(c[i]>='0'&&c[i]<='9') a[i] = c[i] - '0'; else a[i] = c[i] - 'A' + 10; num = max(num, a[i]+1); } return num; } int get(int t, int* a, int n) { int ans = 0; for(int i=0; i<n; i++) ans = ans * t + a[i]; return ans; } int main() { scanf("%s %s", c1, c2); int n1 = strlen(c1); int n2 = strlen(c2); int x1 = fun(c1, a, n1); int x2 = fun(c2, b, n2); bool isok=false; for(int i=x1; i<=36&&!isok; i++) { int t1 = get(i, a, n1); for(int j=x2; j<=36&&!isok; j++) { int t2 = get(j, b, n2); if(t1 == t2) { isok = true; x1 = i; x2 = j; } } } if(!isok) printf("%s is not equal to %s in any base 2..36\n", c1, c2); else printf("%s (base %d) = %s (base %d)\n", c1, x1, c2, x2); return 0; }
抓住青春的尾巴。。。