水题,了解一下代码怎么写就好。
#include<cstdio>
#include<cstring>
#include<cctype>
using namespace std;
int main()
{
char s[105];
char c;
int i=0,first=1;
while((c=getchar())!=EOF)
{
if(c!='\n')
{
if(isalpha(c))
{
if(first)
{
s[i++]=c-32;first=0;
}
else
{
s[i++]=c;
}
}
else
{
first=1;s[i++]=c;
}
}
else
{
s[i]='\0';
printf("%s\n",s);
first=1;i=0;
}
}
return 0;
}
本题在输入的时候就对数据进行了处理,这样更为高效,值得借鉴。(但要注意,如果数据不大,也不必过分追求这种方式,因为这种方式容易出错)