708
1 2 3 4 5 6 7 8 9 10 |
#include <iostream> int main() { for (int i = 1; i <= 100; ++i) { if ((i & 1) == 0) { std::cout << i << std::endl; } } return 0; } |
709
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <iostream> int main() { int input = 0; std::cin >> input; for (int i = 1; i <= input; ++i) { if (i & 1) { std::cout << i << std::endl; } } return 0; } |
712
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <iostream> int main() { int i = 6, count = 0; while (i--) { double a = 0.0; std::cin >> a; if (a > 0) { count++; } } std::cout << count << " positive numbers" << std::endl; return 0; } |
714
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 a = 0, b = 0, sum = 0; std::cin >> a >> b; if (a > b) { a = a + b; b = a - b; a = a - b; } for (int i = a + 1; i < b; ++i) { if (i & 1) { sum += i; } } std::cout << sum << std::endl; return 0; } |
716
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <iostream> int main() { int count = 100, max = 0, index = 0, num = 0; while(count--) { int a = 0; std::cin >> a; num++; if (a > max) { max = a; index = num; } } std::cout << max << std::endl; std::cout << index << std::endl; return 0; } |
721
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> #include <vector> int main() { std::vector<int> vec; int input = 0; do { std::cin >> input; vec.emplace_back(input); } while(input != 0); for (auto item : vec) { if (item != 0) { for (int i = 1; i <= item; ++i) { std::cout << i << " "; } std::cout << std::endl; } } return 0; } |
720
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <iostream> int main() { int a = 0, b = 0, sum = 0; std::cin >> a; while(std::cin >> b, b <= 0) ; for (int i = a; i <= a+b-1; ++i) { sum += i; } std::cout << sum << std::endl; return 0; } |
724
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <iostream> int main() { int n = 0; std::cin >> n; for (int i = 1; i <= n; ++i) { if (n % i == 0) { std::cout << i << std::endl; } } return 0; } |
723
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> int main() { int n = 0, m = 0, start = 1; std::cin >> n >> m; for (int i = 0; i < n; ++i) { for (int j = start; j <= start + m - 1; ++j) { if (j < start + m - 1) { std::cout << j << " "; } else { std::cout << "PUM" << std::endl; start = j + 1; break; } } } return 0; } |
715
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <iostream> int main() { int n = 0; std::cin >> n; for(int i = 1; i < 10000; ++i) { if ((i % n) == 2) { std::cout << i << std::endl; } } return 0; } |
710
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <iostream> int main() { int x = 0; std::cin >> x; int start = (x & 1) ? x : x+1; for (int i = start; i < start+12; ++i) { if (i & 1) { std::cout << i << std::endl; } } return 0; } |
711
1 2 3 4 5 6 7 8 9 10 11 |
#include <iostream> int main() { int a = 0; std::cin >> a; for (int i = 1; i <= 10; ++i) { std::cout << i << " x " << a << " = " << i*a << std::endl; } return 0; } |
718
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 33 34 |
#include <cstdio> #include <iostream> int main() { int n = 0; std::cin >> n; int arr[3] = {0}; while (n--) { int count = 0; char ch; //scanf("%d%c", &count, &ch); std::cin >> count >> ch; if (ch == 'C') { arr[0] += count; } else if (ch == 'R') { arr[1] += count; } else if (ch == 'F') { arr[2] += count; } } int total = arr[0] + arr[1] + arr[2]; std::cout << "Total: " << total << " animals" << std::endl; std::cout << "Total coneys: " << arr[0] << std::endl; std::cout << "Total rats: " << arr[1] << std::endl; std::cout << "Total frogs: " << arr[2] << std::endl; printf("Percentage of coneys: %.2lf \%\n", (arr[0] / static_cast<double>(total))*100.00); printf("Percentage of rats: %.2lf \%\n", (arr[1] / static_cast<double>(total))*100.00); printf("Percentage of frogs: %.2lf \%\n", (arr[2] / static_cast<double>(total))*100.00); return 0; } |
713
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 x = 0; std::cin >> x; int count_in = 0, count_out = 0; while(x--) { int y = 0; std::cin >> y; if (y >= 10 && y <= 20) { count_in++; } else { count_out++; } } std::cout << count_in << " in" << std::endl; std::cout << count_out << " out" << std::endl; return 0; } |
719
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 33 34 |
#include <iostream> #include <vector> int main() { int n = 0; std::cin >> n; std::vector<int> vec; while(n--) { int x = 0, y = 0; std::cin >> x >> y; if (x > y) { x = x+y; y = x-y; x = x-y; } int sum = 0; for (int i = x+1; i < y; ++i) { if (i & 1) { sum +=i; } } vec.emplace_back(sum); } for (auto item : vec) { std::cout << item << std::endl; } return 0; } |
717
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> #include <vector> int main() { int n = 0; std::cin >> n; std::vector<int> vec; for (int i = 0; i < 46; ++i) { if (i == 0 || i == 1) { vec.emplace_back(i); } else { vec.emplace_back(vec[i-1]+vec[i-2]); } } for (int i = 0; i < n; ++i) { std::cout << vec[i] << " "; } return 0; } |
722
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 |
#include <iostream> #include <vector> int main() { int m = 0, n = 0; std::vector<int> vec; while(std::cin >> m >> n, (m>0)&&(n>0)) { if (m > n) { m = m+n; n = m-n; m = m-n; } vec.emplace_back(m); vec.emplace_back(n); } for (int i = 0; i < vec.size(); i += 2) { int sum = 0; for (int j = vec[i]; j <= vec[i+1]; ++j) { sum += j; std::cout << j << " "; } std::cout << "Sum=" << sum << std::endl; } return 0; } |
725
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 33 34 35 36 37 38 39 40 |
#include <iostream> #include <vector> bool perfect(int num) { int sum = 0; for (int i = 1; i*i < num; ++i) { if ((num % i) == 0) { if (i < num) { sum += i; } if (num / i < num && num != num /i) { sum += num/i; } } } return (sum == num); } int main() { int n = 0; std::cin >> n; std::vector<int> vec; while(n--) { int number = 0; std::cin >> number; vec.emplace_back(number); } for (auto item : vec) { if (perfect(item)) { std::cout << item << " is perfect" << std::endl; } else { std::cout << item << " is not perfect" << std::endl; } } return 0; } |
726
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 33 34 35 36 37 |
#include <iostream> #include <vector> #include <cmath> bool prime(int num) { bool flag = true; for (int i = 2; i <= static_cast<int>(sqrt(num)); ++i) { if (num % i == 0) { flag = false; break; } } return flag; } int main() { int n = 0; std::cin >> n; std::vector<int> vec; while(n--) { int number = 0; std::cin >> number; vec.emplace_back(number); } for (auto item : vec) { if (prime(item)) { std::cout << item << " is prime" << std::endl; } else { std::cout << item << " is not prime" << std::endl; } } return 0; } |
727
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> int get_count(int n, int i, int mid) { return n - 2 * abs(mid - i); } int get_start(int count, int mid) { return mid - count/2; } int main() { int n = 0; std::cin >> n; int mid = (n + 1) / 2; int count = 0, start = 0; for (int i = 1; i <= n; ++i) { count = get_count(n, i, mid); start = get_start(count, mid); for (int j = 1; j <= n; ++j) { if (j < start || j > start + count - 1) { std::cout << " "; } else { std::cout << "*"; } } std::cout << std::endl; } return 0; } |
本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 【AcWing 语法基础课 第五讲】02/28
- ♥ 【LeetCode-Mar-链表一】03/24
- ♥ 【LeetCode-30 天 JavaScript 挑战】07/23
- ♥ 【LeetCode-Aug】08/10
- ♥ 【AcWing 语法基础课 第二讲】02/17
- ♥ 【AcWing 语法基础课 第六讲】03/02