工作室ACM竞赛第三周代码记录:
第一题:
1 ZN的随机数 2 3 1 #include <iostream> 4 2 #include <set> 5 3 using namespace std; 6 4 7 5 int main() 8 6 { 9 7 int n; 10 8 while (cin >> n) 11 9 { 12 10 set<int> s; 13 11 for (int i = 0, x; i < n; ++i) 14 12 { 15 13 cin >> x; 16 14 s.insert(x); 17 15 } 18 16 cout << s.size() << endl; 19 17 for (auto it : s) 20 18 { 21 19 cout << it << ' '; 22 20 } 23 21 cout << endl; 24 22 } 25 23 }
第二题:
加班加班加班
第三题:
1 1 #include <iostream> 2 2 using namespace std; 3 3 4 4 int main() 5 5 { 6 6 string str; 7 7 char ch; 8 8 getline(cin, str); 9 9 cin >> ch; 10 10 11 11 string str2; 12 12 for (char c : str) 13 13 { 14 14 if (c != ch) 15 15 { 16 16 str2 += c; 17 17 } 18 18 } 19 19 cout << str2 << endl; 20 20 }
第四题:
1 1 #include <iostream> 2 2 using namespace std; 3 3 4 4 void Char(string& a) 5 5 { 6 6 for (int i = 0; i < a.length(); i++) 7 7 { 8 8 if (a[i] >= 'A' && a[i] <= 'Z') 9 9 { 10 10 if (a[i] == 'Z') 11 11 { 12 12 a[i] = 'a'; 13 13 continue; 14 14 } 15 15 a[i] += 1; 16 16 } 17 17 else if (a[i] >= 'a' && a[i] <= 'z') 18 18 { 19 19 if (a[i] == 'z') 20 20 { 21 21 a[i] = 'A'; 22 22 continue; 23 23 } 24 24 a[i] += 1; 25 25 } 26 26 } 27 27 } 28 28 29 29 int main() 30 30 { 31 31 string a; 32 32 cin >> a; 33 33 Char(a); 34 34 cout << a << endl; 35 35 }
第五题:
1 1 #include <iostream> 2 2 using namespace std; 3 3 4 4 void x(int n, char A, char B, char C) 5 5 { 6 6 if (n == 1) 7 7 { 8 8 cout << 1 << ' ' << A << ' ' << C << endl; 9 9 return; 10 10 } 11 11 x(n - 1, A, C, B); 12 12 cout << n << ' ' << A << ' ' << C << endl; 13 13 x(n - 1, B, A, C); 14 14 } 15 15 16 16 int main() 17 17 { 18 18 int n; 19 19 cin >> n; 20 20 x(n, 'A', 'B', 'C'); 21 21 }