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);
        }
    }
    则每输出一个单词换一行;
  • 相关阅读:
    第三章 AOP
    第二章 IoC
    第一章 Spring 概述
    框架整合
    后台管理工程搭建
    技术架构
    淘淘商城简介
    电商行业背景
    前言
    FutureTask的使用
  • 原文地址:https://www.cnblogs.com/jianglan/p/1777327.html
Copyright © 2011-2022 走看看