/* 2690:首字母大写 查看 提交 统计 提示 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。 在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\t')、回车符('\r')、换行符('\n')。 输入 输入一行:待处理的字符串(长度小于80)。 输出 输出一行:转换后的字符串。 样例输入 if so, you already have a google account. you can sign in on the right. 样例输出 If So, You Already Have A Google Account. You Can Sign In On The Right. 来源 计算概论05*/ #include<stdio.h> #include<string.h> #include <string.h> #include<iostream> using namespace std; char str[82]; int i; int len; int main() { gets(str); len=strlen(str); for(i=0;i<len;i++) { if(i==0) { if(str[i]>='a'&&str[i]<='z') { str[i]-=32; } } else { if(str[i]==' '||str[i]=='\t'||str[i]=='\r'||str[i]=='\n' ||str[i]>'z'||str[i]<'A'||str[i]>'Z'&&str[i]<'a')//因为空白符不在asca11码中。所以要另说 { if(i+1<len&&str[i+1]>='a'&&str[i+1]<='z') str[i+1]-=32; } } } printf("%s\n",str); return 0; }
【字符串处理】openjudge2690首字母大写
猜你喜欢
转载自blog.csdn.net/momo_mo520/article/details/80775352
今日推荐
周排行