zoukankan      html  css  js  c++  java
  • HDU 1062 Text Reverse

    题意 : 给出你一个句子,让你把句子中每个单词的字母顺序颠倒一下输出。

    思路 : 用栈即可,就是注意原来在哪儿有空格就要输出空格。

    //hdu1062
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <stack>
    using namespace std ;
    int main()
    {
        int n ;
        scanf("%d",&n) ;
        getchar() ;
        char ch[1100] ;
        for(int i = 0 ; i < n ; i++)
        {
            stack<char>stk ;
            gets(ch) ;
            int len = strlen(ch) ;
            ch[len] = ' ' ;//最后一个单词输出时的空格
            ch[len+1] = '' ;
            int len1 = strlen(ch) ;
            for(int j = 0; j < len1 ; j++)
            {
                if(ch[j] != ' ')
                    stk.push(ch[j]) ;
                else
                {
                    while(!stk.empty())
                    {
                        char sh = stk.top() ;
                        printf("%c",sh) ;
                        stk.pop() ;
                    }
                    if(j != len1-1)
                        printf("%c",ch[j]) ;//除了最后一个单词后边没有空格之外,其余都有
                }
    
            }printf("
    ") ;
        }
        return 0 ;
    }
    View Code
  • 相关阅读:
    Mysql 删除表
    Mysql 创建表
    Mysql left join
    Qt(Mac) 进程的启动
    Mysql update
    Mysql insert
    Mysql select
    Mysql INNER JOIN
    Mysql 别名
    Mysql 排序
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3456906.html
Copyright © 2011-2022 走看看