返回列表 發帖

602 字串拆解

1. 題目說明:
請依下列題意進行作答,使輸出值符合題意要求。

2. 設計說明:
請撰寫一程式,讓使用者輸入一個包含英文大小寫的字串,並依序將字串中的大、小寫字母分離,最後依序輸出字串中的大寫字串、小寫字串及大寫字母的數量。

提示:若使用 Java 語言答題,請以「JP」開頭命名包含 main 靜態方法的 class,評測系統才能正確評分。

3. 輸入輸出:
輸入說明
一個包含英文大小寫的字串

輸出說明
字串中的大寫字串、小寫字串及大寫字母的數量

範例輸入
ComPuTer
範例輸出
CPT
omuer
3


本帖隱藏的內容需要回復才可以瀏覽

  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. int main()
  4. {
  5.     string str,b,s;
  6.     cin>>str;
  7.     for(char c:str)
  8.     {
  9.         if(c>='a')
  10.             s+=c;
  11.         else
  12.             b+=c;
  13.     }
  14.     cout<<b<<'\n';
  15.     cout<<s<<'\n';
  16.     cout<<b.length();
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str,b,s;
  4. int main()
  5. {
  6.     cin>>str;
  7.     for(char c:str)
  8.     {
  9.         if(c>='a')
  10.             s+=c;
  11.         else
  12.             b+=c;
  13.     }
  14.     cout<<b<<endl;
  15.     cout<<s<<endl;
  16.     cout<<b.length();

  17. }
複製代碼

TOP

  1. #include <iostream>

  2. using namespace std;
  3. string str,b,s;
  4. int main()
  5. {
  6.     cin>>str;
  7.     for(char c : str)
  8.     {
  9.         if(c>='a')
  10.             s+=c;
  11.         else
  12.             b+=c;
  13.     }
  14.     cout <<b<< endl;
  15.     cout<<s<<endl;
  16.     cout<<b.size()<<endl;
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str,b,s;
  4. int main()
  5. {
  6.     cin>>str;
  7.     for(char c:str)
  8.     {
  9.         if(c>='a')
  10.             s+=c;
  11.         else
  12.             b+=c;
  13.     }
  14.     cout<<b<<endl;
  15.     cout<<s<<endl;
  16.     cout<<b.length();
  17. }
複製代碼

TOP

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     string str,u,s;
  6.     cin>>str;
  7.     for(char c:str){
  8.         if(c>='a')
  9.             s+=c;
  10.         else
  11.             u+=c;
  12.     }
  13.     cout<<u<<endl;
  14.     cout<<s<<endl;
  15.     cout<<u.size();
  16.     return 0;
  17. }
複製代碼

TOP

返回列表