hdu2026首字母变大写

来源:互联网 发布:淘宝管控记录是什么 编辑:程序博客网 时间:2024/04/30 03:21

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2026

参考代码一:

#include <stdio.h>
#include <string.h>
int main()
{
 char s[101];
 int i;
 while(gets(s))
 {
  for(i=0;i<strlen(s);i++)
  {
   if(i==0)
    s[i]=s[i]-'a'+'A';
   else if(s[i]==' ')
    s[i+1]=s[i+1]-'a'+'A';
  }
  puts(s);
 }
 return 0;
}

参考代码二:

#include <stdio.h>
#include <string.h>
int main()
{
 char s[101];
 int i;
 while(gets(s))
 {
  s[0]-=32;
  for(i=0;i<strlen(s);i++)
  {
   if(s[i]==' ')
    s[i+1]-=32;;
  }
  puts(s);
 }
 return 0;
}

 

原创粉丝点击