【華爲OJ】統計大寫字母個數

輸入:字符串

輸出:大寫字母的個數


#include<iostream>
#include<string>
using namespace std;

int main()
{
	string str;
	getline(cin,str);
	int count = 0;
	if (str == "")
		cout << 0<<endl;
	else
	{
		for (int i = 0;i < str.size();i++)
		{
			if (str[i]>='A' && str[i]<='Z')
			{
				count++;
			}
		}	
		cout << count << endl;
	}	
	return 0;
}

這道題目很簡單,不過這裏需要判斷字符串爲空的情況(輸出0),用到了getline(cin,str).

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章