2024-05-17 01:36:13
#include <ctype.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
char str[100 + 1];
int isfirst = 1;
char ch;
int i = 0;
while((ch = getchar()) != EOF)
{
if(isalpha(ch))
{
if(isfirst == 1)
{
ch = toupper(ch);
isfirst = 0;
}
}
else
{
isfirst = 1;
}
str[i++] = ch;
}
str[i] = '\0';
printf("%s\n", str);
return 0;
}
其它方法:
def huan(src):
str1='';
len1=len(src);
for i in range(len1):
if(i==0):
str1=chr(ord(src[i])-32);
print(str1,end='');
elif(src[i-1]==' '):
str1=chr(ord(src[i])-32);
print(str1,end='');
else:
str1=src[i];
print(str1,end='');
num1=input('输入字符串:');
huan(num1);