Browse Source

2019-2020-1学期《C程序设计I》:顺序结构【19计算机12班】 题解(OJ基本输入输出 ,简单控制结构)

webturing 4 years ago
parent
commit
9a4aefae95
24 changed files with 297 additions and 0 deletions
  1. 17 0
      A.cpp
  2. 16 0
      B.cpp
  3. 11 0
      C.cpp
  4. 12 0
      D.cpp
  5. 13 0
      E.cpp
  6. 10 0
      F.cpp
  7. 18 0
      G.cpp
  8. 10 0
      H.cpp
  9. 8 0
      I.cpp
  10. 16 0
      J.cpp
  11. 15 0
      K.cpp
  12. 18 0
      L.cpp
  13. 8 0
      M.cpp
  14. 16 0
      N.cpp
  15. 12 0
      O.cpp
  16. 14 0
      P.cpp
  17. 10 0
      Q.cpp
  18. 12 0
      R.cpp
  19. 12 0
      S.cpp
  20. 13 0
      T.cpp
  21. 10 0
      U.cpp
  22. 10 0
      V.cpp
  23. 8 0
      W.cpp
  24. 8 0
      X.cpp

+ 17 - 0
A.cpp

@@ -0,0 +1,17 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main(int argc, char const *argv[]) {
+    double a, b, c;
+    cin >> a >> b >> c;
+    double delta = b * b - 4 * a * c;
+    double x1 = (-b + sqrt(delta)) / (2 * a);
+    double x2 = (-b - sqrt(delta)) / (2 * a);
+    if (x1 < x2) {
+        swap(x1, x2);
+    }
+    cout << fixed << setprecision(2) << x1 << " " << fixed << setprecision(2)
+         << x2 << endl;
+    return 0;
+}

+ 16 - 0
B.cpp

@@ -0,0 +1,16 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int x, y, z;
+    for (x = 0; x < 20; x++)
+        for (y = 1; y < 33; y++) {
+            z = 100 - x - y;
+            if (5 * x + 3 * y + z / 3 == 100 && z % 3 == 0) {
+                cout << "cock=" << x << ",hen=" << y << ",chicken=" << z << endl;
+            }
+        }
+
+    return 0;
+}

+ 11 - 0
C.cpp

@@ -0,0 +1,11 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main(int argc, char const *argv[]) {
+    for (double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;) {
+        cout << setiosflags(ios::fixed) << setprecision(2)
+             << hypot(x1 - x2, y1 - y2) << endl;
+    }
+    return 0;
+}

+ 12 - 0
D.cpp

@@ -0,0 +1,12 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+const double pi = atan(1.0) * 4;
+
+int main(int argc, char const *argv[]) {
+    for (double r; cin >> r;) {
+        cout << setiosflags(ios::fixed) << setprecision(3)
+             << 4.0 * pi * pow(r, 3) / 3 << endl;
+    }
+    return 0;
+}

+ 13 - 0
E.cpp

@@ -0,0 +1,13 @@
+#include <bit/stdc++.h>
+
+using namespace std;
+
+int main(int argc, char const *argv[]) {
+    const double PI = atan(1.0) * 4;
+    int n;
+    double r;
+    for (cin >> n; cin >> r, n--;) {
+        cout << setiosflags(ios::fixed) << setprecision(6) << PI * r * r << endl;
+    }
+    return 0;
+}

+ 10 - 0
F.cpp

@@ -0,0 +1,10 @@
+#include <iostream>
+
+using namespace std;
+
+int main() {
+    for (int n; cin >> n;) {
+        for (int a, b; n-- && cin >> a >> b; cout << (a + b) % 100 << endl);
+    }
+    return 0;
+}

+ 18 - 0
G.cpp

@@ -0,0 +1,18 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main(int argc, char const *argv[]) {
+    for (int m, n; cin >> m >> n;) {
+        int x = 0, y = 0;
+        for (int i = m; i <= n; i++) {
+            if (i % 2) {
+                y += i * i * i;
+            } else {
+                x += i * i;
+            }
+        }
+        cout << x << " " << y << endl;;
+    }
+    return 0;
+}

+ 10 - 0
H.cpp

@@ -0,0 +1,10 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int a, b;
+    cin >> a >> b;
+    cout << a + b << endl;
+    return 0;
+}

+ 8 - 0
I.cpp

@@ -0,0 +1,8 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    cout << "WelCome To Ahstu Online Judge System";
+    return 0;
+}

+ 16 - 0
J.cpp

@@ -0,0 +1,16 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int rev(int n) {
+    int m = 0;
+    for (; n; n /= 10) {
+        m = m * 10 + n % 10;
+    }
+    return m;
+}
+
+int main() {
+    for (int a, b; cin >> a >> b; cout << rev(rev(a) * rev(b)) << endl);
+    return 0;
+}

+ 15 - 0
K.cpp

@@ -0,0 +1,15 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int a, n, m;
+    for (cin >> a; a-- && cin >> n >> m;) {
+        if (n >= 0 && m >= 0 && m % 2 == 0 && m >= 2 * n && m <= 4 * n) {
+            cout << (4 * n - m) / 2 << " " << (m - 2 * n) / 2 << endl;
+        } else {
+            cout << "No answer\n";
+        }
+    }
+    return 0;
+}

+ 18 - 0
L.cpp

@@ -0,0 +1,18 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+void fout(double x, int scale = 6) {
+    cout << setiosflags(ios::fixed) << setprecision(scale) << x << endl;
+}
+
+int main(int argc, char const *argv[]) {
+    double U, D, H, slope, area, perimeter;
+    cin >> U >> D >> H;
+    area = (U + D) * H / 2;
+    slope = hypot((D - U) / 2, H);
+    perimeter = U + D + 2 * slope;
+    fout(area, 2);
+    fout(perimeter, 2);
+    return 0;
+}

+ 8 - 0
M.cpp

@@ -0,0 +1,8 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main(int argc, char const *argv[]) {
+    for (string s; cin >> s; cout << s << endl);
+    return 0;
+}

+ 16 - 0
N.cpp

@@ -0,0 +1,16 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int rev(int n) {
+    int m = 0;
+    for (; n; n /= 10) {
+        m = m * 10 + n % 10;
+    }
+    return m;
+}
+
+int main() {
+    for (int a, b; cin >> a >> b; cout << rev(rev(a) * rev(b)) << endl);
+    return 0;
+}

+ 12 - 0
O.cpp

@@ -0,0 +1,12 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+const double PI = acos(-1.0);
+
+int main() {
+    double r, h;
+    cin >> r >> h;
+    cout << "Area=" << fixed << setprecision(2)
+         << 2 * PI * r * r + 2 * PI * r * h;
+    return 0;
+}

+ 14 - 0
P.cpp

@@ -0,0 +1,14 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int n;
+    cin >> n;
+    int a = n / 100;
+    int b = (n % 100) / 10;
+    int c = n % 10;
+    int m = c * 100 + b * 10 + a;
+    cout << m << endl;
+    return 0;
+}

+ 10 - 0
Q.cpp

@@ -0,0 +1,10 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int a, b;
+    cin >> a >> b;
+    cout << b << " " << a;
+    return 0;
+}

+ 12 - 0
R.cpp

@@ -0,0 +1,12 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+const double PI = acos(-1.0);
+
+int main() {
+    int a[3];
+    cin >> a[0] >> a[1] >> a[2];
+    cout << fixed << setprecision(3) << std::accumulate(a, a + 3, 0) / 3.0;
+    return 0;
+}

+ 12 - 0
S.cpp

@@ -0,0 +1,12 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+const double PI = acos(-1.0);
+
+int main() {
+    double f;
+    cin >> f;
+    cout << fixed << setprecision(3) << 5 * (f - 32) / 9;
+    return 0;
+}

+ 13 - 0
T.cpp

@@ -0,0 +1,13 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+const double PI = acos(-1.0);
+
+int main() {
+    double d;
+    cin >> d;
+    d = d / 180 * PI;
+    cout << fixed << setprecision(3) << sin(d) << " " << fixed << setprecision(3)
+         << cos(d);
+    return 0;
+}

+ 10 - 0
U.cpp

@@ -0,0 +1,10 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    double x1, y1, x2, y2;
+    cin >> x1 >> y1 >> x2 >> y2;
+    cout << fixed << setprecision(3) << hypot(x1 - x2, y1 - y2);
+    return 0;
+}

+ 10 - 0
V.cpp

@@ -0,0 +1,10 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    double f;
+    cin >> f;
+    cout << fixed << setprecision(2) << fabs(f);
+    return 0;
+}

+ 8 - 0
W.cpp

@@ -0,0 +1,8 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    for (int a, b; cin >> a >> b; cout << a + b << endl);
+    return 0;
+}

+ 8 - 0
X.cpp

@@ -0,0 +1,8 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    for (int a; cin >> a; cout << a * a * a << endl);
+    return 0;
+}