zoukankan      html  css  js  c++  java
  • 有趣的C

    在C语言编程时候出现的小问题。原来的要求是:

    Problem Description
    输入一个英文句子,将每个单词的第一个字母改成大写字母。
    Input
    输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。
    Output
    请输出按照要求改写后的英文句子。
    Sample Input
    i like acmi want to get an accepted
    Sample Output
    I Like AcmI Want To Get An Accepted
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int i;
        char a[100];
        while(scanf("%s",a)!=EOF)
        {
            if(a[0]>='a'&&a[0]<='z')
              a[0]-=32;
            for(i=1;i<strlen(a);i++)
              {
                if(a[i]==' ')
                {
                  if(a[i+1]>='a'&&a[i+1]<='z')
                    a[i+1]-=32;
                }
              }
              printf("%s",a);
        }
    }
    这样子输出的格式将吞掉空格;
    如果改为:
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int i;
        char a[100];
        while(scanf("%s",a)!=EOF)
        {
            if(a[0]>='a'&&a[0]<='z')
              a[0]-=32;
            for(i=1;i<strlen(a);i++)
              {
                if(a[i]==' ')
                {
                  if(a[i+1]>='a'&&a[i+1]<='z')
                    a[i+1]-=32;
                }
              }
             puts(a);
        }
    }
    则每输出一个单词换一行;
  • 相关阅读:
    前端模块化开发的价值
    Promise对象
    avalon define新老风格对比
    jQuery知识点1
    SASS
    HTML5
    JSON
    css垂直居中
    maven nexus 部署
    Linux 平台下 lzo和hadoop-lzo安装与集成
  • 原文地址:https://www.cnblogs.com/jianglan/p/1777327.html
Copyright © 2011-2022 走看看