用双指针步进处理
#include<string>
#include<iostream>
using namespace std;
bool isSpliter(char c){//分隔符可能是tab
if(c==' '||c=='\t'||c=='\r'||c=='\n'||c=='\0') return true;
return false;
}
int main(){//习题43 北京大学 首字母大写
//双指针步进即可,用string再split太慢了
//scanf会吃掉空格,用getline
string words;
while(getline(cin,words)){
int i=0,j=0;
while(words[j]!='\0'&&words[i]!='\0'){
while(!isSpliter(words[j])) j++;
if(words[i]<='z' && words[i]>='a') words[i]-=32;
i = ++j;
}
cout<<words<<endl;
}
return 0;
}

京公网安备 11010502036488号