intmain() { int x, y, z; scanf("%d %d %d", &x, &y, &z); int a = x / 3; x = a; y += a; z += a; int b = y / 3; x += b; y = b; z += b; int c = z / 3; x += c; y += c; z = c; printf("%d %d %d", x, y, z); return0; }
自由落体
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<stdio.h>
intmain() { int t; scanf("%d", &t); int h = 10 * t * t / 2; if (h > 2000) { printf("2000"); }else { printf("%d", h); } return0; }
intmain() { char str[4]; double num; int a; scanf("%s %d", &str, &a); num = atof(str); int NUM = num; int min = NUM % 100; int hour = NUM / 100; int res = a + min; if (res >= 60) { int temp = res / 60; hour += temp; res -= temp * 60; }elseif (res < 0) { res = -res; int temp = res / 60; hour -= temp + 1; res -= temp * 60; res = 60 - res; } if (res >= 60) { int temp = res / 60; hour += temp; res -= temp * 60; }
printf("%d%02d", hour, res);
return0; }
输出四位整数的各位数字
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<stdio.h>
intmain() { int num; scanf("%d", &num); int a=num/1000, b=num/100-a*10, c=num/10-a*100-b*10, d=num-a*1000-b*100-c*10; printf("%d=%d+%d*10+%d*100+%d*1000", num, d, c, b, a); return0; }
两小时学完C语言
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<stdio.h>
intmain() { int n, k ,m; scanf("%d %d %d", &n, &k, &m); int remain=n-k*m; printf("%d", remain); return0; }
计算图形面积
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<stdio.h>
intmain() { int a, b; scanf("%d %d", &a, &b); int s=abs(50*a-50*b); printf("%d", s); return0; }
intmain() { int num = 0; int result = 0; int digital = 0; scanf("%d", &num); while (num > 0){ digital = num % 10; result = result * 10 + digital; num /= 10; } printf("%03d", result); return0; }
求三角形面积
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<stdio.h> #include<math.h>
intmain() { double a, b, c; scanf("%lf %lf %lf", &a, &b, &c); double p = (a + b + c) / 2; double s = sqrt(p * (p - a) * (p - b) * (p - c)); printf("%.2f", s); return0; }
intmain() { int n; scanf("%d", &n); int tag = n % 5; switch (tag) { case1: case2: case3: printf("Fishing in day %d", n); break; default: printf("Drying in day %d", n); } return0; }
intmain() { int num; scanf("%d", &num); int a, b, c; a = num / 100; b = num / 10 - a * 10; c = num - a * 100 - b * 10; int A = 1; int B = 1; int C = 1; int cnt = 0; do { A *= a; B *= b; C *= c; cnt++; }while (cnt != 3); int res; res = A + B + C; if (res == num) { printf("YES"); }else { printf("NO"); } return0; }
intmain() { double x = 0.0; scanf ("%lf", &x); double y, z; if (x >= 1 && x < 2) { y = x * x + 1.0; z = 3.0 * x + 5.0; }elseif (x >= 2 && x <= 2.5) { y = x * x + 1.0; z = 2.0 * sin(x) - 1.0; }elseif (x > 2.5 && x < 3) { y = x * x - 1.0; z = 2.0 * sin (x) - 1.0; }elseif (x >= 3 && x < 5) { y = x * x - 1.0; z = sqrt (1.0 + x * x); }elseif (x >= 5 && x < 8) { y = x * x - 1.0; z = x * x - 2 * x + 5; } printf("%lf\n%lf", y, z); return0; }
intmain() { int a, b, c; scanf("%d %d %d", &a, &b, &c); int res; if (a > b) { if (b > c) { res = b; }elseif (a > c) { res = c; }else { res = a; } }elseif (a > c) { res = a; }elseif (b > c) { res = c; }else { res = b; } printf("%d", res); return0; }
intmain() { int n; scanf("%d", &n); int max = 0; int cnt = 1; int num = 0; scanf("%d", &max); for (cnt = 1; cnt < n; cnt++) { scanf("%d", &num); if (num > max) { max = num; } } printf("%d", max); return0; }
for (longlong i = 2; i * i <= n; i++) { longlong temp = 1; longlong k = i; while (temp * k <= n) { temp *= k; if (n % temp == 0 && k - i + 1 > len) { len = k - i + 1; ans = i; } k++; } }
if (len == 0) { printf("1\n%lld\n", n); } else { printf("%lld\n", len); for (int i = 0; i < len; i++) { if (i > 0) printf("*"); printf("%lld", ans + i); } printf("\n"); }
intmain() { int n; scanf("%d", &n); int sum = -1; int i = 2; while (n - sum - i >= 0) { sum += i; i += 4; } int k = i; int j = 1; int u = 1; while (k > 2) { int t = k / 2; int j = u; while (t > 2) { if (t == 3) { printf("*\n"); }else { printf("*"); } t--; } while (j > 0 && k > 6) { printf(" "); j--; } k -= 4; u += 1;
} k = i; u -= 3; int p = 3; int m = 3; while (u >= 0) { j = u; p = m; while (j > 0) { printf(" "); j--; } while (p > 0) { if (p == 1) { printf("*\n"); }else { printf("*"); } p--; } m += 2; u -= 1; }
int difference = n - sum; printf("%d", difference); return0; }
intmain() { int min, max; scanf("%d %d", &min, &max); int tag = min; int mask = 10; int test = 0; int isfirst = 1; for (tag = min; tag <= max; tag++) { int t = tag * tag; int p = tag; mask = 1; while (p > 0) { p /= 10; mask *= 10; } int cur = t % mask; if (cur == tag) { if (isfirst == 1) { printf("%d", tag); test = 1; isfirst = 0; }else{ printf(" %d", tag); } } } if (test == 0) { printf("No exist"); }
intmain() { int m, n; scanf("%d %d", &m, &n); int i = m; int tag = 1; while (i <= n) { int j = 1; int k = i; int mask = 0; while (k > 0) { int num = k % 10; if (num == 5) { mask = 1; break; }else { k /= 10; } } if (i % 3 == 0 && mask == 1) { if (tag == 1) { printf("%d", i); tag = 0; }else { printf(" %d", i); } } i++; } if (tag == 1) { printf("No exist"); } return0; }
intmain() { int n; scanf("%d", &n); int cnt = 0; double res = 0.0; double h = 100.0; int tag = 1; for (cnt = 0; cnt< n; cnt++) { if (tag == 1) { res += 100; tag = 0; }else { h /= 2; res += h*2; } } printf("%lf %lf", res, h/2);
intmain() { int h, f; scanf("%d %d", &h, &f); int c = 0; int r = 0; int res = 0; for (r = 0; r<= h; r++) { c = h - r; if (4*r + 2* c == f) { res = 1; break; } } if (res == 1) { printf ("%d %d", c, r); }else { printf("Error"); } return0; }
intmain() { int n; scanf("%d", &n); int i = 1; int j = 0; int k; int cnt; int p = 1; for (cnt = 0; cnt < n; cnt++) { printf("%10d", i); if (p % 5 == 0 && p!= 0) { printf("\n"); } k = i; i = j + i; j = k; p++; } return0; }
intmain() { int n; scanf("%d", &n); int cnt = 1; int s = 0; do { int count = 1; int cur = 1; while (count <= cnt) { cur = count * cur; count++; } s += cur; cnt++; } while (cnt <= n); printf("%d", s); return0; }
intmain() { int x; scanf("%d", &x); int count = 1; int a = 1;
while (a < x) { a = a * 10 + 1; count++; } printf("%d", a / x); int t = a % x; while (t != 0) { //利用循环将商从高到低位依次输出,直到余数为0。 t = t * 10 + 1; printf("%d", t / x); count++; t %= x; } printf(" %d", count);
intmain() { int num = 1; int temp = 0; int res = 0; while (num > 0) { scanf("%d", &num); if (num > 0) { temp = num % 2; if (temp != 0) { res += num; } } } printf("%d", res); return0; }
猴子吃桃问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<stdio.h>
intmain() { int n; scanf("%d", &n); int res = 1; for (int cnt = 1; cnt < n; cnt++) { res = (res + 1) * 2; } printf("%d", res); return0; }
intmain() { int n; scanf("%d", &n); int first = 1; int i = 1; while (i < n) { first *= 10; i++; } i = first; while (i < first * 10) { int t = i; int sum = 0; do { int d = t % 10; t /= 10; int p = d; int j = 1; while (j < n) { p *= d; j++; } sum += p; } while (t > 0); if (sum == i) { printf("%d\n", i); } i++; } return0; }
intmain() { int num = 0; scanf("%d", &num); int x = num; int temp = 0; int X = 0; int cnt = 1; do { int c = 0; int b = 0; int a = 0; c = x / 100; b = x / 10 - c * 10; a = x - c * 100 - b * 10; if (a > b) { if (b > c) { temp = a * 100 + b * 10 + c; x = c * 100 + b * 10 + a; }elseif (a > c) { temp = a * 100 + c * 10 + b; x = b * 100 + c * 10 + a; }else { temp = c * 100 + a * 10 + b; x = b * 100 + a * 10 + c; } }elseif (a > c) { temp = b * 100 + a * 10 + c; x = c * 100 + a * 10 + b; }elseif (b > c) { temp = b * 100 + c * 10 + a; x = a * 100 + c * 10 + b; }else { temp = c * 100 + b * 10 + a; x = a * 100 + b * 10 + c; } int mask = temp - x; if (mask == 495) { printf("%d: %d - %d = %d", cnt, temp, x, mask); }else { printf("%d: %d - %d = %d\n", cnt, temp, x, mask); } X = x; x = mask; cnt++; }while (temp - X != 495); return0; }
intmain() { int x; scanf("%d", &x); int one; int two; int five; int mask = 0; for (five = x / 5; five != 0; five--) { for (two = x / 2; two != 0; two--) { for (one = x - 1; one != 0; one--) { if (one + two * 2 + five * 5 == x) { int cnt = one + two + five; printf("fen5:%d, fen2:%d, fen1:%d, total:%d\n", five, two, one, cnt); mask++; } } } } printf("count = %d", mask); return0; }
intmain() { int m, n; scanf("%d %d", &m, &n); int cnt = 0; int res = 0; if (m < 2) { m = 2; } for (int t = m; t <= n; t++) { int isPrime = 1; for (int x = 2; x < t; x++) { int rem = t % x; if (rem == 0) { isPrime = 0; break; } } if (isPrime == 1) { res += t; cnt++; } } printf("%d %d", cnt, res); return0; }
intmain() { int n; scanf("%d", &n); double e = 1; double res = 1; for (int num = 1; num <= n; num++) { res = 1; for (int t = 1; t <= num; t++) { res *= t; } e += 1.0 / res; } printf("%.8f", e); return0; }
求平方与倒数序列的部分和
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<stdio.h>
intmain() { double m, n; scanf("%lf %lf", &m, &n); double s = 0; for ( ; m <= n; m++) { s += m * m + 1.0 / m; } printf("%.6f", s); return0; }
intmain() { int n, m; scanf("%d %d", &n, &m); double N = 1; for (int numN = 1; numN <= n; numN++) { N *= numN; } double M = 1; for (int numM = 1; numM <= m; numM++) { M *= numM; } double C = 1; for (int numC = 1; numC <= m - n; numC++) { C *= numC; } double res = M / N / C; printf("%.0f", res); return0; }