标签:timus 1601. anticaps 修正大写句子
| input | output |
|---|---|
HI THERE! HOW DID YOU KNOW I AM A BLONDE? |
Hi there! How did you know i am a blonde? |
就是修正个全是大写的句子。
这里注意一点(as in codes‘ comment):
keep the state, because blonde would do anything, and put the comma, in one line, and start typing another line.
#include <string>
#include <iostream>
using namespace std;
void toLowerCase(string &s, bool &senBegin)
{
for (unsigned i = 0; i < s.size(); i++)
{
if (‘ ‘ == s[i]) continue;
if (senBegin)
{
if (‘A‘ <= s[i] && s[i] <= ‘Z‘ || ‘a‘ <= s[i] && s[i] <= ‘z‘)
{
s[i] = toupper(s[i]);
senBegin = false;
}
continue;
}
if (‘.‘ == s[i] || ‘?‘ == s[i] || ‘!‘ == s[i]) senBegin = true;
s[i] = tolower(s[i]);
}
}
int AntiCAPS1601()
{
string s;
bool senBegin = true;//keep the state, because blonde would do anything, and put the comma, in one line, and start typing another line.
while (getline(cin, s))
{
toLowerCase(s, senBegin);
cout<<s<<endl;
}
return 0;
}
标签:timus 1601. anticaps 修正大写句子
原文地址:http://blog.csdn.net/kenden23/article/details/24642747