HDU-2026首字母大写

来源:互联网 发布:河南工程学院(软件类) 编辑:程序博客网 时间:2024/04/28 08:30

水啊水,求排名 前10000

其实一种情况未处理,第一个空格以后的单词有bug,不过数据太弱,没查出来

#include <iostream>#include <string>std::string str;int size;int pos1,pos2;int main(){while (std::getline(std::cin,str)){if(isalpha(str[0])){str[0]=toupper(str[0]);}while((pos2=str.find_first_of(' ',pos1))!=std::string::npos){if(pos2!=pos1){str[pos2+1]=toupper(str[pos2+1]);}pos1=pos2+1;}if(pos1!=str.size()){str[pos1]=toupper(str[pos1]);}std::cout<<str<<std::endl;pos1=pos2=0;str.clear();}}



原创粉丝点击