ACM“新生杯”第二次周赛

发布时间 2023-04-05 01:23:35作者: X1Cherry

啧,只存草稿没发(wd问题)(编于4.4)

来到ACM天梯赛考核的第二周,第一周进行的还算顺利,来看看第二周又有哪些考题吧!

第一题需要注意的是各个条件判断的细节,以及层级包含关系:

 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     string s1, s2;
 6     int flag = 2;
 7     cin >> s1;
 8     cin >> s2;
 9     if (s1.length() != s2.length())
10     {
11         cout << 1 << endl;
12     }
13     else
14     {
15         for (int i = 0; i < s1.length(); i++)
16         {
17 
18             if (s1[i] != s2[i])
19             {
20 
21                 if (s1[i] + 32 == s2[i] || s1[i] - 32 == s2[i])
22                 {
23 
24                     flag = 3;
25                 }
26                 else
27                 {
28                     flag = 4;
29                     break;
30                 }
31             }
32         }
33         cout << flag << endl;
34     }
35 }
只要我安排的够快,烦恼就追不上我

第二题:注意多个for循环的嵌套关系,不要套错and要注意最后的输出结果标准,主要还是排列啦,类比:“冒泡排序”。:

 1 #include<iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     for (int i = 1; i <= 9; i++)
 7         for (int j = 0; j <= 9; j++)
 8             for (int z = 0; z <= 9; z++)
 9             {
10                 if ((i * i * i + j * j * j + z * z * z) == (i * 100 + j * 10 + z))
11                     cout << (i * 100 + j * 10 + z) << endl;
12             }
13 }
我左看右看上看下看 原来每个排列都不简单

第三题:

  1 #include <iostream>
  2 using namespace std;
  3 
  4 int main()
  5 {
  6     int m, n;
  7     char t[26];
  8     cin  >> n  >> m;
  9 
 10     for (int i = 0; i < n; i++)
 11     {
 12         if (i == 0)
 13         {
 14             for (int j = 0; j < m; j++)
 15                 t[j] = 'A' + j;
 16         }
 17 else
 18 {
 19     for (int j = m - 1; j >:j--)
 20         t[j] = t[j - 1];
 21     t[0] = 'A' + i;
 22 }
 23 for (int j  = 0; j < m; j++)
 24     cout << t[j];
 25 cout << endl;
 26 
 27     }
 28 }
 29 
 30 
 31 
 32 #include<iostream>
 33 using namespace std;
 34 
 35 int main() {
 36     int n; //用作接收数组长度
 37     cin  >> n;
 38     int* a  = new int[n]; //指针的动态内存分配
 39 
 40     for (int i  = 0; i  < n; i++)
 41     {
 42         cin  >> a[i]; //为数组赋值
 43     }
 44 
 45     //选择排序
 46     for (int i  = 0; i  < n - 1; i++)
 47     {
 48         int min  = i;
 49         for (int k  = min + 1; k  < n; k++)
 50         {
 51             if (a[min] > a[k])
 52             {
 53                 int temp  = a[min];
 54                 a[min] = a[k];
 55                 a[k] = temp;
 56             }
 57         }
 58     }
 59 
 60     for (int i  = 0; i  < n; i++) //控制输出格式
 61     {
 62         cout  << a[i] << " ";
 63     }
 64     cout  << endl;
 65 
 66     delete[] a;
 67     return 0;
 68 }
 69 
 70 
 71 
 72 
 73 
 74 #include<iostream>
 75 using namespace std;
 76 
 77 int main()
 78 {
 79     for (int i = 1; i <= 9; i++)
 80         for (int j = 0; j <= 9; j++)
 81             for (int z = 0; z <= 9; z++)
 82             {
 83                 if ((i * i * i + j * j * j + z * z * z) == (i * 100 + j * 10 + z))
 84                     cout << (i * 100 + j * 10 + z) << endl;
 85             }
 86     return 0;
 87 }
 88 
 89 
 90 
 91 
 92 
 93 
 94 
 95 
 96 #include <iostream>
 97 using namespace std;
 98 int main()
 99 {
100     int n;
101     int m;
102     cin  >> n;
103     int array[1000];
104     for (int i  = 0; i  < n; i++)
105     {
106         cin  >> array[i];
107     }
108     cin  >> m ;
109     for (int i  = 0; i  < n; )
110     {
111         if (array[i] == m)
112         {
113             cout  << i + 1;
114             break;
115         }
116         i++;
117         if (i  == n )
118         {
119             cout  << -1 << endl;
120             break;
121         }
122     }
123 }
不止这么简单

第四题:

 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     int m;
 7     cin  >> n;
 8     int array[1000];
 9     for (int i  = 0; i  < n; i++)
10     {
11         cin  >> array[i];
12     }
13     cin  >> m ;
14     for (int i  = 0; i  < n; )
15     {
16         if (array[i] == m)
17         {
18             cout  << i + 1;
19             break;
20         }
21         i++;
22         if (i  == n )
23         {
24             cout  << -1 << endl;
25             break;
26         }
27     }
28 }
胖子行动队
第五题:
 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     int m;
 7     cin  >> n;
 8     int array[1000];
 9     for (int i  = 0; i  < n; i++)
10     {
11         cin  >> array[i];
12     }
13     cin  >> m ;
14     for (int i  = 0; i  < n; )
15     {
16         if (array[i] == m)
17         {
18             cout  << i + 1;
19             break;
20         }
21         i++;
22         if (i  == n )
23         {
24             cout  << -1 << endl;
25             break;
26         }
27     }
28 }
体育考试