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);
        }
    }
    则每输出一个单词换一行;
  • 相关阅读:
    gulp通过http-proxy-middleware开启反向代理,实现跨域
    一些我常用的css 或者 js
    四舍五入
    生成 SSH 公钥
    对象转为数组 用lodash
    廖雪峰的官方网站
    window对象
    字符串
    简单得日期
    LeetCode 113. Path Sum II 20170705 部分之前做了没写的题目
  • 原文地址:https://www.cnblogs.com/jianglan/p/1777327.html
Copyright © 2011-2022 走看看