返回列表 發帖

601 大小寫轉換

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

2. 設計說明:
請撰寫一程式,讓使用者輸入一個字串及自然數n,n為字串的索引值,請判斷索引值為n的字元,若為大寫,則將大寫轉成小寫;若為小寫,則將小寫轉成大寫,並替換成新的字串,最後輸出大小寫轉換後的字元與字串。

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

3. 輸入輸出:
輸入說明
一個字串及自然數n

輸出說明
大小寫轉換後的字元與字串

範例輸入
abcdef
3

範例輸出
The letter that was selected is: D
abcDef


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

本帖最後由 吳侑諶 於 2024-9-3 20:37 編輯
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. string a;
  4. int b;
  5. int main()
  6. {
  7.     cin>>a>>b;
  8.     char c;
  9.     if(a[b]>='a' && a[b]<='z')
  10.         a[b]-=32;
  11.     else
  12.         a[b]+=32;
  13.     cout<<"The letter that was selected is: "<<a[b]<<endl;
  14.     cout<<a;
  15.     return 0;
  16. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int n;
  5. int main()
  6. {
  7.     cin>>str>>n;
  8.     if(str[n]>='a'){
  9.         str[n]-=32;
  10.     }else{
  11.         str[n]+=32;
  12.     }
  13.     cout<<"The letter that was selected is: "<<str[n]<<endl;
  14.     cout<<str;
  15.     return 0;
  16. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int n;
  5. int main()
  6. {
  7.     cin>>str>>n;
  8.     char c=str[n];
  9.     if(c>='a')
  10.     {
  11.         c=c-32;
  12.         str[n]=str[n]-32;
  13.     }
  14.     else
  15.     {
  16.         c=c+32;
  17.         str[n]=str[n]+32;
  18.     }
  19.     cout<<"The letter that was selected is: "<<c<<'\n';
  20.     cout<<str;
  21.     return 0;
  22. }
複製代碼

TOP

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n;
  6.     string str;
  7.     cin>>str>>n;
  8.     if(str[n]<='Z')
  9.         str[n]+=32;
  10.     else
  11.         str[n]-=32;
  12.     cout<<"The letter that was selected is: "<<str[n]<<endl;
  13.     cout<<str;
  14.     return 0;
  15. }
複製代碼

TOP

  1. #include <bits/stdc++.h>

  2. using namespace std;
  3. string str;
  4. int x;
  5. int main()
  6. {
  7.     cin>>str>>x;
  8.     char c=str[x];
  9.     if(c>='a')
  10.     {
  11.         c-=32;
  12.         str[x]=c;
  13.     }else
  14.     {
  15.         c+=32;
  16.         str[x]=c;
  17.     }
  18.     cout<<"The letter that was selected is: "<<c<<endl;
  19.     cout<<str;
  20.     return 0;
  21. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int n;
  5. int main()
  6. {
  7.     cin>>str>>n;
  8.     if(str[n]>='a')
  9.     {
  10.         str[n]=str[n]-32;
  11.     }
  12.     else
  13.     {
  14.         str[n]=str[n]+32;
  15.     }
  16.     cout<<"The letter that was selected is: "<<str[n]<<endl;
  17.     cout<<str;
  18. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int n;
  5. int main()
  6. {
  7.     cin>>str>>n;
  8.     char c=str[n];
  9.     if(c>='a')
  10.     {
  11.         c=c-32;
  12.         str[n]=str[n]-32;
  13.     }
  14.     else
  15.     {
  16.         c=c+32;
  17.         str[n]=str[n]+32;
  18.     }
  19.     cout<<"The letter that was selected is: "<<c<<'\n';
  20.     cout<<str;
  21.     return 0;
  22. }
複製代碼

TOP

返回列表