团体程序设计天梯赛-练习集L16-L26(除L20和L25)

16.

 1 #pragma GCC optimize(3)//pta檢查身份證 
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 int n;
 5 char ch[12]={'1','0','X','9','8','7','6','5','4','3','2'};
 6 string s;
 7 int flag;
 8 int a[20]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
 9 int main()
10 {
11     std::ios::sync_with_stdio(false);
12     cin>>n;
13     for(register int i=1;i<=n;i++)
14     {
15         int sum=0;
16         cin>>s;
17         for(register int j=0;j<17;j++)
18         {
19             sum+=((s[j]-'0')*a[j]); 
20         }
21         sum%=11;
22         if(s[17]!=ch[sum])
23         {
24             flag++;
25             cout<<s<<endl;
26         }
27     }
28     if(flag==0)
29     cout<<"All passed"<<endl; 
30     return 0;
31 }

17.

 1 /*#pragma GCC optimize(3)//pta 到底有多2 
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 int main()
 5 {
 6     std::ios::sync_with_stdio(false);
 7     char a[100];
 8     int i,j,h;
 9     scanf("%s",a);
10     int lena;
11     lena=strlen(a);
12     int count=0;
13     for(i=0;i<lena;i++)
14     {
15         if(a[i]=='2')
16         count++;
17     }
18     double rate;
19     if(a[0]=='-')
20     {
21         if(a[lena-1]%2==0)
22         {
23             rate=count*1.0/(lena-1)*1.0*1.5*2.0*100;
24         }
25         else
26         {
27             rate=count*1.0/(lena-1)*1.0*1.5*100;
28         }
29     }
30     else
31     {
32         if(a[lena-1]%2==0)
33         {
34             rate=count*1.0/lena*1.0*2.0*100;
35         }
36         else
37         {
38             rate=count*1.0/lena*1.0*100;
39         }
40     }
41     printf("%.2f%%",rate);
42         
43     
44 }*/

18.

 1 /*#include<bits/stdc++.h>//pta 大笨鈡 
 2 using namespace std;
 3 int h;
 4 int m;
 5 char ch;
 6 int main()
 7 {
 8     std::ios::sync_with_stdio(false);
 9     cin>>h>>ch>>m;
10     if(h<12)
11     {
12         printf("Only %02d:%02d.  Too early to Dang.",h,m);
13     }
14     else if(h==12&&m==0)
15     {
16         printf("Only %02d:%02d.  Too early to Dang.",h,m);
17     }
18     else
19     {
20         if(m==0)
21         {
22             int n=h%12;
23             for(register int i=1;i<=n;i++)
24             {
25                 cout<<"Dang";
26             }
27         }
28         else
29         {
30             int n=h%12+1;
31             for(register int i=1;i<=n;i++)
32             cout<<"Dang";
33         }
34     }
35     return 0;
36 }*/

19.

 1 *#include<bits/stdc++.h>//pta誰先倒 
 2 using namespace std;
 3 int main()
 4 {
 5     std::ios::sync_with_stdio(false);
 6     int a,b;
 7     cin>>a>>b;
 8     int n;
 9     cin>>n;
10     int numa=0,numb=0;
11     for(int i = 1;i <= n;i ++ )
12     {
13         int a1,a2,b1,b2;
14         cin>>a1>>a2>>b1>>b2;
15         if((a2==(a1+b1)&&b2==(a1+b1))||(a2!=(a1+b1)&&b2!=(a1+b1)))
16         {
17             continue;
18         }
19         if(a2==(a1+b1))//甲输
20         {
21             numa++;
22             if(numa>a)
23             {
24                 cout<<'A'<<endl;
25                 cout<<numb;
26                 break;
27             }
28         } 
29         if(b2==(a1+b1))
30         {
31             numb++;
32             if(numb>b)
33             {
34                 cout<<'B'<<endl;
35                 cout<<numa;
36                 break;
37             }
38             
39         }
40     } 
41 }*/

20.明天做

21.水了

22.水

23.

 1 #include<bits/stdc++.h>//pta 输出GPLT 
 2 using namespace std;
 3 int g;
 4 int t;
 5 int l;
 6 int p;
 7 string s;
 8 int main()
 9 {
10     std::ios::sync_with_stdio(false);
11     cin>>s;
12     for(register int i=0;i<s.length();i++)
13     {
14         s[i]=toupper(s[i]);
15         if(s[i]=='G')
16         {
17             g++;
18         }
19         else if(s[i]=='T')
20         {
21             t++;
22         }
23         else if(s[i]=='L')
24         {
25             l++;
26         }
27         else if(s[i]=='P')
28         {
29             p++;
30         } 
31     }
32     while(g||t||l||p)
33     {
34         if(g>0)
35         {
36             cout<<'G';
37             g--;
38         }
39          if(p>0)
40         {
41             cout<<'P';
42             p--;
43         }
44          if(l>0)
45         {
46             cout<<'L';
47             l--;
48         }
49          if(t>0)
50         {
51             cout<<'T';
52             t--;
53         }
54     }
55     return 0;
56 }*/

24.水

25.明天做,這個題涉及到一個c語言的標準庫,明天好好研究一下

26.水

 

posted @ 2022-04-12 20:12  江上舟摇  阅读(26)  评论(0编辑  收藏  举报