输入一行:待处理的字符串(长度小于100)。
可能有多组测试数据,对于每组数据, 输出一行:转换后的字符串。
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.
#include <stdio.h>
#include <string.h>
char aToA(char ch) {
return ch - 'a' + 'A';
}
int main() {
char str[100];
while (gets(str)) { // 注意 while 处理多个 case
if (str[0] >= 'a' && str[0] <= 'z')
str[0] = aToA(str[0]);
int len = strlen(str);
for (int i = 1; i < len - 1; i++) {
if ((str[i] == ' ' || str[i] == '\t' || str[i] == '\t' || str[i] == '\n') &&
(str[i + 1] >= 'a' && str[i + 1] <= 'z'))
str[i + 1] = aToA(str[i + 1]);
}
printf("%s", str);
}
return 0;
} #include <stdio.h>
#define N 101
int main(){
char s[N];
fgets(s, N, stdin);
if (s[0]>='a'&&s[0]<='z') {
s[0] += 'A'-'a';
}
for (int i = 1; s[i]!='\n'; i ++) {
if ((s[i-1]==' '||s[i-1]=='\t'||s[i-1]=='\r'||s[i]=='\n')&&(s[i]>='a'&&s[i]<='z')) {
s[i] += 'A'-'a';
}
}
puts(s);
} #include <stdio.h>
#include <string.h>
#include <ctype.h>
#define maxn 105
char temp[maxn];
char s[maxn];
int main()
{
while(fgets(temp, maxn, stdin) != NULL)
{
temp[strlen(s) - 1] = '\0';
char *sp = temp;
int num;
for(num = 0;sscanf(sp, "%s", s) != EOF; num++)
{
*sp = toupper(*sp);
sp += strlen(s);
while (isspace(*sp))
sp++;
}
printf("%s\n", temp);
}
return 0;
} #include<stdio.h>
#include<string.h>
int main(){
char s[100];
while(gets(s)){
for(int i=0;i<strlen(s);i++){
if(i==0 && (s[i] >=97 && s[i]<=122))
s[i]-=32;
if((s[i]==' ' ||s[i]=='\t' ||s[i]=='\n' ||s[i]=='\r') && (s[i+1]>=97 && s[i+1]<=122))
s[i+1]-=32;
}
for(int i=0;i<strlen(s);i++){
printf("%c",s[i]);
}
printf("\n");
}
}
有些投机取巧了,不过还是比较简短的