ACM“新生杯”第三次周赛

发布时间 2023-04-04 01:28:04作者: X1Cherry

今天是ACM“新生杯”的第三周了,工作室的考核时间也已过半,目前时间还是很紧张的。今天的题目很难,为了调试而没有一个个交,后几个都留到了一起才交,也新学到了很多东西/思想。好啦~那让我们来看看代码吧!


首先是第一个,“ZN的随机数”:
这个程序用到了“随机数”的概念,但我们用的不是rand,而是随即输入,并使用set系统容器去存储,再用set进行去重,最后再输出!好,一起来看看代码吧~!

ZN的随机数
 1 #include <iostream>
 2 #include <set>
 3 using namespace std;
 4 
 5 int main() 
 6 {
 7     int n;
 8     while (cin >> n)
 9     {
10         set<int> s;
11         for (int i = 0, x; i < n; ++i)
12         {
13             cin >> x;
14             s.insert(x);
15         }
16         cout << s.size() << endl;
17         for (auto it : s)
18         {
19             cout << it << ' ';
20         }
21         cout << endl;
22     }
23 }

 

第二个 “加班加班加班”:

注意精确小数那一块需要的技巧

 1 #include <iostream>
 2 #include <iomanip>
 3 using namespace std;
 4 
 5 double Wage3(int hour, double wage1)
 6 {
 7     if (hour <= 40)
 8     {
 9         return hour * wage1;
10     }
11     else if (hour <= 50)
12     {
13         return 40 * wage1 + (hour - 40) * wage1 * 1.5;
14     }
15     else
16     {
17         return 40 * wage1 + 10 * wage1 * 1.5 + (hour - 50) * wage1 * 2;
18     }
19 }
20 
21 int main()
22 {
23     int hour;
24     double wage1;
25     while (cin >> hour >> wage1) 
26     {
27         double wage2 = Wage3(hour, wage1);
28         cout << fixed << setprecision(2) << wage2 << endl;
29     }
30 }
加班

 

第三个“消灭雷同”

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main() 
 5 {
 6     string str;
 7     char ch;
 8     getline(cin, str); 
 9     cin >> ch;
10 
11     string str2; 
12     for (char c : str) 
13     { 
14         if (c != ch) 
15         { 
16             str2 += c;
17         }
18     }
19     cout << str2 << endl; 
20 }
消灭雷同

 

第四题“

 1 #include <iostream>
 2 using namespace std;
 3 
 4 void Char(string& a)
 5 {
 6     for (int i = 0; i < a.length(); i++) 
 7    {
 8         if (a[i] >= 'A' && a[i] <= 'Z') 
 9        {
10             if (a[i] == 'Z') 
11            {
12                 a[i] = 'a';
13                 continue;
14             }
15             a[i] += 1;
16         } 
17             else if (a[i] >= 'a' && a[i] <= 'z') 
18            {
19             if (a[i] == 'z') 
20             {
21                 a[i] = 'A';
22                 continue;
23             }
24             a[i] += 1;
25         }
26     }
27 }
28 
29 int main() 
30 {
31     string a;
32     cin >> a;
33     Char(a);
34     cout << a << endl;
35 }
密电加密

 

第五题,嗨嗨嗨,“宝石?”

 1 #include <iostream>
 2 using namespace std;
 3 
 4 void x(int n, char A, char B, char C) 
 5 {
 6     if (n == 1)
 7    {
 8         cout << 1 << ' ' << A << ' ' << C << endl;
 9         return;
10     }
11     x(n - 1, A, C, B);
12     cout << n << ' ' << A << ' ' << C << endl;
13     x(n - 1, B, A, C);
14 }
15 
16 int main() 
17 {
18     int n;
19     cin >> n;
20     x(n, 'A', 'B', 'C');
21 }
第五题宝石剑?