hdu 2577 How to Type - 水題

/*
hdu 2577 How to Type
*/
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	int ret,on;
	int t;
	cin>>t;
	while(t--)
	{
		ret=on=0;
		cin>>s;
		int i,len=s.length();
		for(i=0;i<len;++i)
		{
			if(s[i]>='A'&&s[i]<='Z')
			{
				if(on==1)
					ret++;
				else
				{
					if(i==(len-1))
					{
						ret+=2;
					}else if(s[i+1]>='A'&&s[i+1]<='Z')
					{
						ret+=2;
						on=1;
					}else
					{
						ret+=2;
					}
				}
			}else
			{
				if(on==0)
					ret++;
				else
				{
					if(i==(len-1))
					{
						ret+=2;
						on=0;
					}else if(s[i+1]>='a'&&s[i+1]<='z')
					{
						ret+=2;
						on=0;
					}else//大寫字母按shift也可以變大寫字母
					{
						ret+=2;
					}
				}
			}
		}
		if(on)
			ret++;
		cout<<ret<<endl;
	}
	return 0;
}

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