zoukankan      html  css  js  c++  java
  • Reversed Words

    Time Limit: 2000 ms Memory Limit: 131072 KiB

     

    Problem Description

    Some aliens are learning English. They have a very strange way in writing that they revered every word in the sentence but keep all the words in common order. For example when they want to write “one two three”, they will write down “eno owt eerht”.

    Now we’ve got some sentence written by these aliens, translate them! And maybe we will know some of their secrets!

    Input

     Multiple test cases. The first line contains a positive integer T (T <= 1000), indicating the number of test cases.

    For each test cases, there will be one line contains only lower case letters and spaces. The length of each line will be no more than 10000. Test cases which are longer than 5000 will be less than 50. Continuous letters are seen as a word, words are separated by spaces. There won’t be two adjacent spaces in the input. Space won’t be the first or the last character.

    Output

     One line per case, the translated sentence.

    Sample Input

    2
    eno owt eerht
    abcde
    

    Sample Output

    one two three
    edcba

    大意是:给你一串字符串(包含多个有空格分隔的子字符串),将每个子字符串前后倒置后并输出。
    我想了一个特别的方法:先将所有字符倒置,再从后往前输出每个子字符串。
    贴下我写的代码:
    #include<stdio.h>
    #include<string.h>
    int main ()
    {
        int e;
        while(scanf("%d",&e)!=EOF)
        {
            getchar();
            while(e--)
            {
                int n,i;
                char s[10010]={0},t;
                gets(s);
                n=strlen(s);
                for(i=0;i<n/2;i++)
                {
                    t=s[i];
                    s[i]=s[n-i-1];
                    s[n-i-1]=t;
                }
                for(i=n-1;i>=0;i--)
                {
                    if(s[i]!=' ')
                        continue;
                    printf("%s ",&s[i+1]);
                    s[i]=0;
                }
                printf("%s
    ",&s[0]);
            }
        }
        return 0;
    }

    Hint

  • 相关阅读:
    召开演示会议和总结会议
    召开每天的站立会议
    禅道管理中的项目管理--组织进行任务分解
    linux sort,uniq,cut,wc命令详解
    json2.js的用途(拯救IE)
    memcache的内存回收机制
    memcache内存分配机制
    Linux之Sed命令详解(总结一些实用例子)
    CentOS 设置网络(修改IP&修改网关&修改DNS)--update.14.08.15
    php中文字符串翻转
  • 原文地址:https://www.cnblogs.com/coder-tcm/p/8627607.html
Copyright © 2011-2022 走看看