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);
        }
    }
    则每输出一个单词换一行;
  • 相关阅读:
    struts2工作流程
    单播,多播(组播),广播,详细讲解呀
    UDP和TCP两种协议的传输数据长度分析
    内置方法 call enter exit
    内置方法 new-del
    内置方法 str-repr
    疏忽知识点记忆(待补充)
    判断一个数据类型的属性的多种方法与判断是否是继承
    反射
    初始化,实例化
  • 原文地址:https://www.cnblogs.com/jianglan/p/1777327.html
Copyright © 2011-2022 走看看