zoukankan      html  css  js  c++  java
  • 算法提高 逆序排列

    http://lx.lanqiao.org/problem.page?gpid=T215

    算法提高 逆序排列  
    时间限制:1.0s   内存限制:512.0MB
        
    问题描述
      编写一个程序,读入一组整数(不超过20个),并把它们保存在一个整型数组中。当用户输入0时,表示输入结束。然后程序将把这个数组中的值按逆序重新存放,并打印出来。例如:假设用户输入了一组数据:7 19 -5 6 2 0,那么程序将会把前五个有效数据保存在一个数组中,即7 19 -5 6 2,然后把这个数组中的值按逆序重新存放,即变成了2 6 -5 19 7,然后把它们打印出来。
      输入格式:输入只有一行,由若干个整数组成,中间用空格隔开,最末尾的整数为0。
      输出格式:输出也只有一行,即逆序排列后的整数,中间用空格隔开,末尾没有空格。
      输入输出样例
    样例输入
    7 19 -5 6 2 0
    样例输出
    2 6 -5 19 7
     
    分析:
     
    倒序输出即可。
     
     
    AC代码:
     
     1 #include <stdio.h>
     2 #include <algorithm>
     3 #include <iostream>
     4 #include <string.h>
     5 #include <string>
     6 #include <math.h>
     7 #include <stdlib.h>
     8 #include <queue>
     9 #include <stack>
    10 #include <set>
    11 #include <map>
    12 #include <list>
    13 #include <iomanip>
    14 #include <vector>
    15 #pragma comment(linker, "/STACK:1024000000,1024000000")
    16 #pragma warning(disable:4786)
    17 
    18 using namespace std;
    19 
    20 const int INF = 0x3f3f3f3f;
    21 const int Max = 10000 + 10;
    22 const double eps = 1e-8;
    23 const double PI = acos(-1.0);
    24 
    25 int main()
    26 {
    27     int a[21] , i = 0 , temp;
    28     while(scanf("%d",&temp))
    29     {
    30         if(temp != 0)
    31         {
    32             a[i ++] = temp;
    33             continue;
    34         }
    35         else
    36         {
    37             int j;
    38             for(j = i - 1;j >= 0 ;j --)
    39                 if(j == i - 1)
    40                     printf("%d",a[j]);
    41                 else
    42                     printf(" %d",a[j]);
    43             puts("");
    44             break;
    45         }
    46     }
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    Java并发编程:synchronized
    对一致性Hash算法,Java代码实现的深入研究
    在Xcode中使用Git进行源码版本控制
    这些 Git 技能够你用一年了
    简明 Git 命令速查表
    Git 分支管理是一门艺术
    2016年Web前端面试题目汇总
    iOS 面试基础题目
    Json数据交互格式介绍和比较
    SpringBoot端口和访问路径
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4450754.html
Copyright © 2011-2022 走看看