L1-023+032
阿新 • • 發佈:2022-04-20
題目連結
https://pintia.cn/problem-sets/994805046380707840/problems/994805113036587008
https://pintia.cn/problem-sets/994805046380707840/problems/994805100684361728 getchar
放AC程式碼
1 #include<bits/stdc++.h> 2 using namespace std; 3 string s; 4 int g,p,l,t; 5 int main() 6 { 7 cin>>s; 8 for(unsigned int i=0;i<s.length();i++) 9 { 10 s[i]=toupper(s[i]); 11 if(s[i]=='G') g++; 12 else if(s[i]=='P') p++; 13 else if(s[i]=='L') l++; 14 else if(s[i]=='T') t++; 15 } 16 while(g||p||l||t) 17 { 18 if(g>0) {cout<<'G'; g--;} 19 if(p>0) {cout<<'P'; p--;} 20 if(l>0) {cout<<'L'; l--;} 21 if(t>0) {cout<<'T'; t--;} 22 } 23 return 0; 24 }
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n; 4 char ch; 5 string s; 6 int main() 7 { 8 cin>>n>>ch; 9 getchar();10 getline(cin,s); 11 if(n>s.length()) 12 { 13 for(unsigned int i=0;i<n-s.length();i++) 14 cout<<ch; 15 cout<<s; 16 } 17 else 18 { 19 for(unsigned int i=s.length()-n;i<s.length();i++) 20 cout<<s[i]; 21 } 22 return 0; 23 }