返回列表 發帖

[隨堂測驗] 字串處理 (十一) - 判斷大小寫


Tips:index從0開始,到字串長度-1
要知道是大寫字母還是小寫字母就來看看ASCII字元表
可以看到大寫(A~Z)為65~90小寫(a~z)為97~122
虛擬碼:
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str;
  8.     cout<<"請輸入一字串(包含空白,100字內): ";
  9.     //取得使用者輸入
  10.     ?????
  11.     cout<<"每個字元之大小寫依序為: "<<endl;
  12.     //index從0開始,到字串長度-1(不會=字串長度)
  13.     for(int i=0; i<?????; i++)
  14.     {
  15.         cout<<"第"<<i+1<<"個字元的ASCII碼為"<<int(str[i])<<", ";
  16.         //小寫(a~z)為97~122
  17.         if(int(str[i])>=97 && int(str[i])<=122)
  18.              cout<<"小寫!"<<endl;
  19.         //大寫(A~Z)為65~90
  20.         else if(???????)
  21.              cout<<"大寫!"<<endl;
  22.         else
  23.              cout<<"該字元不是英文字母!"<<endl;
  24.     }
  25.     system("pause");
  26.     return 0;   
  27. }
複製代碼
本帖隱藏的內容需要積分高於 10 才可瀏覽

此帖僅作者可見

TOP

此帖僅作者可見
Attention Seeker </3

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

返回列表