737
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <iostream> int main() { int arr[10] = {0}; int i = 0; while (std::cin >> arr[i], i++, i < 10) ; for (int i = 0; i < 10; ++i) { if (arr[i] <= 0) { std::cout << "X[" << i << "] = " << 1 << std::endl; } else { std::cout << "X[" << i << "] = " << arr[i] << std::endl; } } return 0; } |
738
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <iostream> int main() { int x = 0; std::cin >> x; int start = x; for (int i = 0; i < 10; ++i) { std::cout << "N[" << i << "] = " << start << std::endl; start *= 2; } return 0; } |
739
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <iostream> #include <cstdio> int main() { double input = 0.0; int count = 0; while(std::cin >> input, count <100) { if (input <= 10.0) { printf("A[%d] = %.1lf\n", count, input); } count++; } return 0; } |
734
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> double get_sum(double item[], int length) { double sum = 0.0; for (int i = 0; i < length; ++i) { sum += item[i]; } return sum; } int main() { int line = 0; char ch; std::cin >> line >> ch; double item[12][12] = {0.0}; for (int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> item[i][j]; } } if (ch == 'S') { printf("%.1lf\n", get_sum(item[line], 12)); } else if (ch == 'M') { printf("%.1lf\n", get_sum(item[line], 12)/12.0); } return 0; } |
745
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> #include <cstdio> int main() { char ch; std::cin >> ch; double arr[12][12] = {0.0}; for(int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> arr[i][j]; } } double sum = 0.0; for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (j > i) { sum += arr[i][j]; } } } if (ch == 'S') { printf("%.1lf\n", sum); } else if (ch == 'M') { printf("%.1lf\n", sum/66.0); } return 0; } |
747
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> #include <cstdio> int main() { char ch; std::cin >> ch; double arr[12][12] = {0.0}; for(int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> arr[i][j]; } } double sum = 0.0; for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (j < 11-i) { sum += arr[i][j]; } } } if (ch == 'S') { printf("%.1lf\n", sum); } else if (ch == 'M') { printf("%.1lf\n", sum/66.0); } return 0; } |
749
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> #include <cstdio> int main() { char ch; std::cin >> ch; double arr[12][12] = {0.0}; for(int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> arr[i][j]; } } double sum = 0.0; for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (i < 5 && j > i && j < 11-i) { sum += arr[i][j]; } } } if (ch == 'S') { printf("%.1lf\n", sum); } else if (ch == 'M') { printf("%.1lf\n", sum/30.0); } return 0; } |
751
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> #include <cstdio> int main() { char ch; std::cin >> ch; double arr[12][12] = {0.0}; for(int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> arr[i][j]; } } double sum = 0.0; for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (j < 5 && i > j && i < 11-j) { sum += arr[i][j]; } } } if (ch == 'S') { printf("%.1lf\n", sum); } else if (ch == 'M') { printf("%.1lf\n", sum/30.0); } return 0; } |
753
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <iostream> int main() { int n = 0; while(std::cin >> n, n > 0) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { int u = i, d = n - i + 1, l = j, r = n - j + 1; std::cout << std::min(std::min(u,d), std::min(l,r)) << " "; } std::cout << std::endl; } std::cout << std::endl; } return 0; } |
740
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> int main() { int n = 0; int arr[20] = {0}; while(std::cin >> arr[n], n++, n<20) ; for (int i = 0; i < 10; ++i) { arr[i] = arr[i] + arr[19-i]; arr[19-i] = arr[i] - arr[19-i]; arr[i] = arr[i] - arr[19-i]; } for (int i = 0; i < 20; ++i) { std::cout << "N[" << i << "] = " << arr[i] << std::endl; } return 0; } |
741
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include <iostream> long get_fib(int i) { if (i == 0) { return 0; } else if (i == 1) { return 1; } else { long a = 0, b = 1, c = 0; for (int j = 2; j <= i; ++j) { c = a + b; a = b; b = c; } return c; } } int main() { int n = 0, num = 0; std::cin >> n; while(std::cin >> num, n--) { std::cout << "Fib(" << num << ") = " << get_fib(num) << std::endl; } return 0; } |
742
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <iostream> int main() { int n = 0, item = 0, min = 0, index = 0, count = 0; std::cin >> n; while(std::cin >> item, n--) { if (count == 0) { min = item; index = 0; } else { if (min > item) { min = item; index = count; } } count++; } std::cout << "Minimum value: " << min << std::endl; std::cout << "Position: " << index << std::endl; return 0; } |
744
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <iostream> #include <cstdio> int main() { int line = 0; char ch; std::cin >> line >> ch; double arr[12][12] = {0.0}; for(int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> arr[i][j]; } } double sum = 0.0; for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (j == line) { sum += arr[i][j]; } } } if (ch == 'S') { printf("%.1lf\n", sum); } else if (ch == 'M') { printf("%.1lf\n", sum/12.0); } return 0; } |
748
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> #include <cstdio> int main() { char ch; std::cin >> ch; double arr[12][12] = {0.0}; for(int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> arr[i][j]; } } double sum = 0.0; for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (j >= 12-i) { sum += arr[i][j]; } } } if (ch == 'S') { printf("%.1lf\n", sum); } else if (ch == 'M') { printf("%.1lf\n", sum/66.0); } return 0; } |
746
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> #include <cstdio> int main() { char ch; std::cin >> ch; double arr[12][12] = {0.0}; for(int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> arr[i][j]; } } double sum = 0.0; for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (j < i) { sum += arr[i][j]; } } } if (ch == 'S') { printf("%.1lf\n", sum); } else if (ch == 'M') { printf("%.1lf\n", sum/66.0); } return 0; } |
750
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> #include <cstdio> int main() { char ch; std::cin >> ch; double arr[12][12] = {0.0}; for(int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> arr[i][j]; } } double sum = 0.0; for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (i > 6 && j > 11-i && j < i) { sum += arr[i][j]; } } } if (ch == 'S') { printf("%.1lf\n", sum); } else if (ch == 'M') { printf("%.1lf\n", sum/30.0); } return 0; } |
752
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> #include <cstdio> int main() { char ch; std::cin >> ch; double arr[12][12] = {0.0}; for(int i = 0; i < 12; ++i) { for(int j = 0; j < 12; ++j) { std::cin >> arr[i][j]; } } double sum = 0.0; for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (j > 6 && i < j && i > 11-j) { sum += arr[i][j]; } } } if (ch == 'S') { printf("%.1lf\n", sum); } else if (ch == 'M') { printf("%.1lf\n", sum/30.0); } return 0; } |
745
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> int main() { int n = 0; while(std::cin >> n, n > 0) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (i == j) { std::cout << 1 << " "; } else if (j < i) { std::cout << i-j+1 << " "; } else { std::cout << j-i+1 << " "; } } std::cout << std::endl; } std::cout << std::endl; } return 0; } |
755
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include <iostream> #include <cmath> int main() { int n = 0; while(std::cin >> n, n > 0) { long long start = 1; for (int i = 1; i <= n; ++i) { long long temp = start; for (int j = 1; j <= n; ++j) { if (i == j) { std::cout << static_cast<int>(pow(2, (i-1)*2)) << " "; } else if (j < i) { temp *= 2; std::cout << temp << " "; } else { temp = pow(2, (i-1)*2)*pow(2, j-i); std::cout << temp << " "; } } std::cout << std::endl; start = pow(2, i-1); } std::cout << std::endl; } return 0; } |
756
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <iostream> int res[100][100]; int main() { int n = 0, m = 0; std::cin >> n >> m; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; for (int x = 0, y = 0, d = 0, k = 1; k <= n*m; ++k) { res[x][y] = k; int a = x + dx[d], b = y + dy[d]; if (a < 0 || a >= n || b < 0 || b >= m || res[a][b]) { d = (d+1)%4; a = x + dx[d]; b = y + dy[d]; } x = a; y = b; } for (int i = 0 ; i < n; ++i) { for (int j = 0; j < m; ++j) { std::cout << res[i][j] << " "; } std::cout << std::endl; } return 0; } |
本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 【LeetCode-July】07/10
- ♥ 【LeetCode-30 天 JavaScript 挑战】07/23
- ♥ 【LeetCode-Apr-链表二】04/02
- ♥ 【AcWing 语法基础课 第三讲】02/22
- ♥ 【AcWing 语法基础课 第七八讲】03/03
- ♥ 【AcWing 语法基础课 第二讲】02/17