单词首字母大写
输入一个英文句子,要求将每个单词的首字母改成大写字母。
输入格式:
测试数据有多组,处理到文件尾。每组测试输入一行,包含一个长度不超过100的英文句子(仅包含大小写英文字母和空格),单词之间以一个空格间隔。
输出格式:
对于每组测试,输出按照要求改写后的英文句子。
输入样例:
I like acm
i want to get accepted
输出样例:
I Like Acm
I Want To Get Accepted
出处:
HDOJ 2026
#include"stdio.h"
main(){
char str[1000],max;
int i,a,t;
while(gets(str)!=EOF){
t=strlen(str);
max=str[0];
for(i=0;i<t;i++){
if(max<str[i]){
max=str[i];
}
}
for(i=0;i<t;i++){
printf("%c",str[i]);
if(str[i]==max)
printf("(max)");
}
puts(" ");
}
}
#include<stdio.h>
#include<string.h>
int main() {
char str[1000], word[100];
int i, j, t;
while(gets(str)) {
t = strlen(str);
j = 0;
memset(word, 0, sizeof(word));
for(i = 0; i < t; i++) {
if(str[i] != ' ') {
word[j++] = str[i];
} else {
if(word[0] >= 'a' && word[0] <= 'z') {
word[0] -= 32;
}
printf("%s ", word);
memset(word, 0, sizeof(word));
j=0;
}
}
if(word[0] >= 'a' && word[0] <= 'z') {
word[0] -= 32;
}
printf("%s\n", word);
}
return 0;
}
觉得有用的话采纳一下哈