zoukankan      html  css  js  c++  java
  • C语言编程练习5:词组缩写

      要注意

    所有单词由一个或多个空格分隔,有如下几种特殊情况;

    1,“end of file ”
    3,“  end    of   file”
    3,“end    of   file  ”
    4,“  end    of   file  ”
    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    int main()
    {
    	int n;
    	char s[110];
    	scanf("%d",&n);
    	getchar();//取换行符
    	while(n--)
    	{
    		gets(s);//不要用scanf,cin遇到空格会默认结束
    		for(int i = 0;i < (int)strlen(s);i++)
    		{
    			if(i==0)//单独考虑第一个字符
    			{
    				if(s[i] >= 'a'&& s[i] <= 'z')
    				{
    					s[i]-=32;
    					printf("%c",s[i]);
    				}
    				else if(s[i] >= 'A'&& s[i] <= 'Z')
    				{
    					printf("%c",s[i]);
    				}
    			}
    			if(s[i] == ' ')//跳过所有空格
    			{
    				while(s[i] == ' ')
    				{
    					i++;
    				}
    				if(s[i] >= 'a'&& s[i] <= 'z')//空格后遇到的第一个字符
    				{
    					s[i]-=32;
    					printf("%c",s[i]);
    				}
    				else if(s[i] >= 'A'&& s[i] <= 'Z')
    				{
    					printf("%c",s[i]);
    				}
    			}
    		}
    		printf("
    ");
    	}
    	return 0;
    }
    
  • 相关阅读:
    用户交互语句
    基础数据类型补充与总结
    Python 中表示 False 的方法
    集合
    字典
    元组
    列表
    整型数据详述和进制转换
    f-strings 详解
    字符串方法详解
  • 原文地址:https://www.cnblogs.com/FantasticDoubleFish/p/14304686.html
Copyright © 2011-2022 走看看