L1-005+007+008
阿新 • • 發佈:2022-04-19
題目連結:
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 場寬
005:
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,m; 4 intb[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> 2using 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 }