zoukankan      html  css  js  c++  java
  • Problem : (1.2.1) Text Reverse

    #include<iostream>
    using namespace std;
    void main()
    {
    	char arr[1000];
    	int a,n;
    	int s,t;
    	cin>>a;
    	getchar();
    	for(int i=0;i<a;i++)
    	{
    		gets(arr);
    		n=strlen(arr);
    		s=0;
    		for(int j=0;j<=n;j++)
    		{
    			if(arr[j]==' '||arr[j]=='')
    				{
    					t=j;
    					for(int l=t-1;l>=s;l--)
    					{
    						cout<<arr[l];
    					}
    					s=t+1;
    					if(s!=n+1)
    						cout<<" ";
    				}
    			
    
    		}
    		cout<<endl;
    	}
    }

    Problem Description
    Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.
     
    Input
    The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
    Each test case contains a single line with several words. There will be at most 1000 characters in a line.
     
    Output
    For each test case, you should output the text which is processed.
     
    Sample Input
    3
    olleh !dlrow
    m'I morf .udh
    I ekil .mca
     
    Sample Output
    hello world!
    I'm from hdu.
    I like acm.
    
    <div style="" border-bottom:="" #b7cbff="" 1px="" dashed;="" border-left:="" padding-bottom:="" 6px;="" padding-left:="" padding-right:="" font-family:="" times"="">
    Hint
    Remember to use getchar() to read ' ' after the interger T, then you may use gets() to read a line and process it.

    极简,专注,速度,极致
  • 相关阅读:
    python基础12-语法
    基础篇-内置函数(常用)
    中级篇-内置函数 (map/filter/reduce)
    python 基础11-递归
    python 基础10-函数、变量
    python 基础9-拼接
    redis
    python--os模块
    函数return多个值
    python--文件读写
  • 原文地址:https://www.cnblogs.com/simplelifestyle/p/3761927.html
Copyright © 2011-2022 走看看