Browse Source

2019-2020-1学期《C语言程序设计I》:循环结构II【19计算机12班】

zj 4 years ago
parent
commit
8298c4c31e
16 changed files with 307 additions and 0 deletions
  1. 19 0
      1390A.cpp
  2. 22 0
      1390B.cpp
  3. 15 0
      1390C.cpp
  4. 19 0
      1390D.cpp
  5. 15 0
      1390D2.cpp
  6. 13 0
      1390E.cpp
  7. 25 0
      1390F.cpp
  8. 25 0
      1390Fb.cpp
  9. 13 0
      1390G.cpp
  10. 13 0
      1390H.cpp
  11. 25 0
      1390I.cpp
  12. 15 0
      1390J.cpp
  13. 26 0
      1390K.cpp
  14. 20 0
      1390L.cpp
  15. 21 0
      1390M.cpp
  16. 21 0
      1390N.cpp

+ 19 - 0
1390A.cpp

@@ -0,0 +1,19 @@
+#include<bits/stdc++.h>
+using namespace std;
+int main() {
+    int n;
+    cin >> n;
+    while (n > 1) {
+        if (n & 1) {
+            cout << n << "*3+1=";
+            n = 3 * n + 1;
+            cout << n << endl;
+        }
+        else {
+            cout << n << "/2=";
+            n /= 2;
+            cout << n << endl;
+        }
+    }
+    return 0;
+}

+ 22 - 0
1390B.cpp

@@ -0,0 +1,22 @@
+#include<bits/stdc++.h>
+using namespace std;
+int main() {
+    for (int m = 1; m <= 1000000; m++) {
+        int n = m, s = 0;
+        while (n > 0) {
+            int k = n % 10;
+            int p = 1;
+            for (int j = k; j >= 2; j--) {
+                p *= j;
+            }
+            s += p;
+            n /= 10;
+        }
+        if (s == m) {
+            cout << m << " ";
+        }
+    }
+    cout << endl;
+    return 0;
+}
+ 

+ 15 - 0
1390C.cpp

@@ -0,0 +1,15 @@
+#include <bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    for (int i = 32; i < 100; i++) {
+        int m = i * i;
+        int high = m / 100;
+        int low = m % 100;
+        if (high % 11 == 0 && low % 11 == 0) {
+            cout << m << endl;
+        }
+    }
+    return 0;
+}

+ 19 - 0
1390D.cpp

@@ -0,0 +1,19 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    ///Input Process Output
+    int N;
+    cin >> N;
+    while (N--) {
+        int n = 5;
+        cin >> n;
+        int s = 0;
+        for (int i = 1; i <= n; i++) {
+            s += i * (i + 1) / 2;
+        }
+        cout << s << endl;
+    }
+    return 0;
+}

+ 15 - 0
1390D2.cpp

@@ -0,0 +1,15 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    ///Input Process Output
+    int N;
+    cin >> N;
+    while (N--) {
+        int n = 5;
+        cin >> n;
+        cout << n * (n + 1) * (n + 2) / 6 << endl;
+    }
+    return 0;
+}

+ 13 - 0
1390E.cpp

@@ -0,0 +1,13 @@
+#include<bits/stdc++.h>
+using namespace std;
+int main() {
+    int n;
+    cin >> n;
+    for (int i = 1; i <= n; i++) {
+        for (int j = 1; j <= i; j++) {
+            cout << "*";
+        }
+        cout << endl;
+    }
+    return 0;
+}

+ 25 - 0
1390F.cpp

@@ -0,0 +1,25 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int a;
+    cin >> a;
+    while (a--) {
+        int n = 10, m = 16;
+        cin >> n >> m;
+        bool flag = false; ///false=0 true=1
+        for (int x = 0; x <= n; x++)
+            for (int y = 0; y <= n; y++) {
+                if (x + y == n && 2 * x + 4 * y == m) {
+                    cout << x << " " << y << endl;
+                    flag = true;
+                    break;
+                }
+            }
+        if (!flag) {
+            cout << "No answer" << endl;
+        }
+    }
+    return 0;
+}

+ 25 - 0
1390Fb.cpp

@@ -0,0 +1,25 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int a;
+    cin >> a;
+    while (a--) {
+        int n = 10, m = 16;
+        cin >> n >> m;
+        bool flag = false; ///false=0 true=1
+        for (int x = 0; x <= n; x++) {
+            int y = n - x;
+            if (2 * x + 4 * y == m) {
+                cout << x << " " << y << endl;
+                flag = true;
+                break;
+            }
+        }
+        if (!flag) {
+            cout << "No answer" << endl;
+        }
+    }
+    return 0;
+}

+ 13 - 0
1390G.cpp

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

+ 13 - 0
1390H.cpp

@@ -0,0 +1,13 @@
+#include<bits/stdc++.h>
+using namespace std;
+int main() {
+    for (int n; cin >> n; ) {
+        int s = 0;
+        while (n) {
+            s += n % 10;
+            n /= 10;
+        }
+        cout << s << endl;
+    }
+    return 0;
+}

+ 25 - 0
1390I.cpp

@@ -0,0 +1,25 @@
+#include<bits/stdc++.h>
+using namespace std;
+int main() {
+    for (int n; cin >> n; ) {
+        if (n == 0) {
+            cout << "0-->0" << endl;
+            continue;
+        }
+        cout << n << "-->";
+        if (n < 0) {
+            n *=- 1;
+            cout << '-';
+        }
+        int m = n, k = 0;
+        while (m) {
+            k++;
+            m /= 2;
+        }
+        for (int i = k - 1; i >= 0; i--) {
+            cout << ((n >> i) & 1);
+        }
+        cout << endl;
+    }
+    return 0;
+}

+ 15 - 0
1390J.cpp

@@ -0,0 +1,15 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int n;
+    while (cin >> n) {
+        int s = 1;
+        for (int k = n; k >= 2; k -= 2) {
+            s *= k;
+        }
+        cout << s << endl;
+    }
+    return 0;
+}

+ 26 - 0
1390K.cpp

@@ -0,0 +1,26 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    for (int n = 2; n <= 1000; n++) {
+        int s = 1;
+        for (int i = 2; i * i <= n; i++) {
+            if (n % i == 0) {
+                s += i;
+                if (i * i != n)
+                    s += n / i;
+            }
+        }
+        if (s == n) {
+            cout << n << " its factors are 1";
+            for (int i = 2; i <= n / 2; i++) {
+                if (n % i == 0) {
+                    cout << "," << i;
+                }
+            }
+            cout << endl;
+        }
+    }
+    return 0;
+}

+ 20 - 0
1390L.cpp

@@ -0,0 +1,20 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int h, w, z = 0;
+    while (cin >> h >> w) {
+        if (h == 0 and w == 0)
+            break;
+        if (z++)
+            cout << endl;
+        for (int x = 0; x < h; x++) {
+            for (int y = 0; y < w; y++) {
+                cout << "#";
+            }
+            cout << endl;
+        }
+    }
+    return 0;
+}

+ 21 - 0
1390M.cpp

@@ -0,0 +1,21 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int h, w, z = 0;
+    while (cin >> h >> w) {
+        if (h == 0 and w == 0)
+            break;
+        if (z++)
+            cout << endl;
+        for (int x = 0; x < h; x++) {
+            for (int y = 0; y < w; y++) {
+                if (x == 0 || x == h - 1 || y == 0 || y == w - 1)cout << "#";
+                else cout << ".";
+            }
+            cout << endl;
+        }
+    }
+    return 0;
+}

+ 21 - 0
1390N.cpp

@@ -0,0 +1,21 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int h, w, z = 0;
+    while (cin >> h >> w) {
+        if (h == 0 and w == 0)
+            break;
+        if (z++)
+            cout << endl;
+        for (int x = 0; x < h; x++) {
+            for (int y = 0; y < w; y++) {
+                if ((x + y) % 2 == 0)cout << "#";
+                else cout << ".";
+            }
+            cout << endl;
+        }
+    }
+    return 0;
+}