刘木生
111
#include <iostream> using namespace std; string s; char arr[6] = {}; bool test(char a){ if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') return true; return false; } int main (){ cin >> s; for (int i = 0; i < s.size(); i ++){ if (test(s[i])) cout << s[i]; } return 0; } 第 2题题目较乱, 说是要题目自己的函数,最后发下截图。 现在我先不管要求,自己先照着输出先写了 #include <iostream> using namespace std; int x, arr[100005], ans[10]; string s[10] = {"0", "0 - 24 ","25 - 49 ","50 - 74 ","75 - 99 ","100 - 124 ","125 - 149 ","150 - 174 ","175 - 200 "}; int main (){ freopen("testScore.txt","r",stdin); ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int cnt = 1; while(cin >> x){ arr[cnt ++] = x; } for (int i = 1; i <= 8; i++) ans[i] = 0; for (int i = 1; i < cnt; i ++){ if(arr[i] >= 0 && arr[i] <= 24)ans[1] ++; if (arr[i] >= 25 && arr[i] <= 49) ans[2] ++; if (arr[i] >= 50 && arr[i] <= 74) ans[3] ++; if (arr[i] >= 75 && arr[i] <= 99) ans[4] ++; if (arr[i] >= 100 && arr[i] <= 124) ans[5] ++; if (arr[i] >= 125 && arr[i] <= 149) ans[6] ++; if (arr[i] >= 150 && arr[i] <= 174) ans[7] ++; if (arr[i] >= 175 && arr[i] <= 200) ans[8] ++; } for (int i = 1; i <= 8; i ++){ cout << s[i] << ans[i] << '\n'; } return 0; } 第三题 题中说a,b之间,并不知道是闭区间还是开区间,代码写的是前闭后闭 #include <iostream> using namespace std; long long a, b, ans = 0; int main (){ cin >> a >> b; for (int i = a; i <= b; i ++){ if (i % 2) ans += (i * i); } cout << ans; return 0; }