L1-005+007+008+016+017

题目链接:

https://pintia.cn/problem-sets/994805046380707840/problems/994805140211482624 结构体

https://pintia.cn/problem-sets/994805046380707840/problems/994805136889593856 switch语句

https://pintia.cn/problem-sets/994805046380707840/problems/994805135224455168 场宽

https://pintia.cn/problem-sets/994805046380707840/problems/994805122985476096 字符串

https://pintia.cn/problem-sets/994805046380707840/problems/994805121500692480 double


 

005:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int n,m;
 4 int b[1010];
 5 
 6 struct student
 7 {
 8     long long num;
 9     int test;
10     int exam;
11 }a[1010];
12 
13 int main()
14 {
15     cin>>n;
16     for(int i=1;i<=n;i++)
17         cin>>a[i].num>>a[i].test>>a[i].exam;
18     cin>>m;
19     for(int i=1;i<=m;i++)
20         cin>>b[i];
21     for(int i=1;i<=m;i++)
22     {
23         for(int j=1;j<=n;j++)
24         {
25             if(b[i]==a[j].test)
26             {
27                 cout<<a[j].num<<" "<<a[j].exam<<endl;
28             }
29         }
30     }
31     return 0;
32 }

007:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     char ch[1010];
 6     cin>>ch;
 7     int len=strlen(ch);
 8     for(int i=0;i<len;i++)
 9     {
10         switch(ch[i])
11         {
12             case'-':cout<<"fu";break;
13             case'0':cout<<"ling";break;
14             case'1':cout<<"yi";break;
15             case'2':cout<<"er";break;
16             case'3':cout<<"san";break;
17             case'4':cout<<"si";break;
18             case'5':cout<<"wu";break;
19             case'6':cout<<"liu";break;
20             case'7':cout<<"qi";break;
21             case'8':cout<<"ba";break;
22             case'9':cout<<"jiu";break;
23         }
24         if(i<len-1) cout<<' ';
25     }
26     return 0;
27 }

008:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int a,b,x;
 4 int cnt;//记录已输出多少数字
 5 int main()
 6 {
 7     cin>>a>>b;
 8     for(int i=a;i<=b;i++)
 9     {
10         cnt++;
11         if(cnt%5==0&&i!=b)
12             cout<<setw(5)<<i<<endl;
13         else
14             cout<<setw(5)<<i;
15         x+=i;
16     }
17     cout<<endl;
18     cout<<"Sum"<<' '<<"="<<' '<<x<<endl;
19     return 0;
20 }

 016:

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

017:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char ch[60];
 4 int len,sum;
 5 double rate;
 6 int main()
 7 {
 8     cin>>ch;
 9     len=strlen(ch);
10     for(int i=0;i<len;i++)
11     {
12         if(ch[i]=='2')
13             sum++;
14     }
15     if(ch[0]=='-')
16     {
17         if(ch[len-1]%2==0)
18             rate=sum*1.0/(len-1)*1.0*1.5*2.0*100;
19         else
20             rate=sum*1.0/(len-1)*1.0*1.5*100;
21     }
22     else
23     {
24         if(ch[len-1]%2==0)
25             rate=sum*1.0/len*1.0*2.0*100;
26         else
27             rate=sum*1.0/len*1.0*100;
28     }
29     printf("%.2f%%",rate);
30     return 0;
31 }

 

posted @ 2022-04-19 14:18  爱吃虾滑  阅读(27)  评论(0编辑  收藏  举报