1:
#include <bits/stdc++.h> using namespace std; int main() { int n = 10; double MAX, AVG = 0; cin >> AVG; MAX = AVG; for(int i = 1; i < n; i++){ double x; cin >> x; MAX = max(MAX, x); AVG += x; } AVG /= 10; cout << MAX << " " << AVG << endl; return 0; }
2:
#include <bits/stdc++.h> using namespace std; int main() { int a = 1, b = 1, n, sum = 2; cin >> n; if(n == 1){ cout << 1 << endl; }else if(n == 2){ cout << 2 << endl; } for(int i = 3; i <= n; i++){ int c = a + b; sum += c; a = b; b = c; } cout << sum << endl; return 0; }
3:
#include <bits/stdc++.h> using namespace std; int main() { int a[25][25], n; memset(a, 0, sizeof(a));//记得初始化 cin >> n; a[1][1] = 1; for(int i = 2; i <= n; i++){ for(int j = 1; j <= i; j++){ a[i][j] = a[i - 1][j] + a[i - 1][j - 1]; } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= i; j++){ cout << a[i][j] << " "; } cout << endl; } return 0; }
4:
#include <bits/stdc++.h> using namespace std; bool is_prime(int x){ if(x < 2)return 0; if(x == 2)return 1; for(int i = 2; i <= sqrt(x); i++){ if(x % i == 0)return 0; } return 1; } bool is_huiwen(int x){ string s = to_string(x); int l = s.length(); for(int i = 0; i < l / 2; i++){ if(s[i] != s[l - i - 1])return 0; } return 1; } int main() { int x, y; cin >> x >> y; for(int i = x; i <= y; i++){ if(is_prime(i) && is_huiwen(i)) cout << i << endl; } return 0; }
5:
#include <bits/stdc++.h> using namespace std; void f(int x){ if(x){ printf("%d", x % 10); f(x / 10); } } int main() { int x, y; cin >> x; f(x); return 0; }
6:
#include <bits/stdc++.h> using namespace std; int main() { string s; int x = 0, y = 0, k = 0, ans; char c; cin >> s; while(s[k] >= '0' && s[k] <= '9'){ x = x * 10 + s[k] - '0'; k++; } c = s[k++]; while(s[k] >= '0' && s[k] <= '9'){ y = y * 10 + s[k] - '0'; k++; } if(c == '+') ans = x + y; else if(c == '-') ans = x - y; else if(c == '*') ans = x * y; else if(c == '/') ans = x / y; cout << ans << endl; return 0; }
7:
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a; int n = 100; for(int i = 0; i < n; i++){ int x; cin >> x; //位运算 判断x是否为奇数 if(x & 1) a.push_back(x); } sort(a.begin(),a.end()); for(int i = 0; i < a.size(); i++){ cout << a[i] << endl; } return 0; }
8:
标签:std,892.2020,int,namespace,cin,using,include From: https://www.cnblogs.com/rongrongrong/p/16943160.html