参考大佬的链接:https://blog.youkuaiyun.com/Iridescent1018/article/details/100152681
#include <stdio.h>
#include <string.h>
int main(){
char str[110];
while(gets(str)){
int len = strlen(str);
//对第一个字符单独处理 特例是第一个字符为空白字符
//即" nihao" 输出还需是" nihao",而不是" Nihao"
if(str[0]>'Z'){
str[0] = str[0] + 'A' - 'a';
}
for(int i=1; i<len; i++){
if(str[i]==' '||str[i]=='\t'||str[i]=='\r'||str[i]=='\n'){
while(str[i]==' '||str[i]=='\t'||str[i]=='\r'||str[i]=='\n'){
i++;
}
if(str[i]>'Z'){
str[i] = str[i] + 'A' - 'a';
}
}
}
printf("%s\n", str);
}
return 0;
}
/*
//错在没考虑第一个字符时空白字符的情况!
int main(){
char s[110];
while(gets(s)){
int len=strlen(s);
int str[110][110], row=0, col=0;
for(int i=0; i<110; i++){
for(int j=0; j<110; j++){
str[i][j] = '\0';
}
}
for(int i=0; i<len; i++){
if((s[i]!=' ')&&(s[i]!='\t')&&(s[i]!='\r')&&(s[i]!='\n')){
str[row][col++] = s[i];
}else{
str[row][col] = '\0';
row++;
col = 0;
}
}
for(int i=0; i<=row; i++){
if(str[i][0]>='A' && str[i][0]<='Z'){
printf("%c", str[i][0]);
}else if(str[i][0] >'Z'){
printf("%c", (str[i][0]+'A'-'a'));
}
col = 1;
while(str[i][col] != '\0'){
printf("%c", str[i][col]);
col++;
}
printf(" ");
}
printf("\n");
}
return 0;
}
*/
3012

被折叠的 条评论
为什么被折叠?



