Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1544883
  • 博文数量: 327
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 3556
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-05 21:28
个人简介

东黑布衣,流浪幽燕。 真诚善良,值得信赖。

文章分类

全部博文(327)

我的朋友

分类: BSD

2016-10-18 14:59:55


  1. // aha0206.cpp : Defines the entry point for the console application.
  2. //
  3. #include <stdio.h>
  4. #include "stdafx.h"


  5. int _tmain(int argc, _TCHAR* argv[])
  6. {
  7.     int data[101],right[101];
  8.     int i,n,t,len;
  9.     freopen("aha0206i.txt","r",stdin);
  10.     freopen("aha0206o.txt","w",stdout);
  11.     setbuf(stdout,NULL);

  12.     scanf("%d",&n);
  13.     for(i=1;i<=n;i++)
  14.         scanf("%d",&data[i]);
  15.     len=n;
  16.     for(i=1;i<=n;i++)
  17.     {
  18.         if(i!=n)
  19.             right[i]=i+1;
  20.         else
  21.             right[i]=0;
  22.     }
  23.     len++;
  24.     scanf("%d",&data[len]);
  25.     t=1;
  26.     while(t!=0)
  27.     {
  28.         if(data[right[t]] > data[len])
  29.         {
  30.             right[len]=right[t];
  31.             right[t]=len;
  32.             break;
  33.         }
  34.         t=right[t];
  35.     }

  36.     t=1;
  37.     while(t!=0)
  38.     {
  39.         printf("%d ",data[t]);
  40.         t=right[t];
  41.     }
  42.     getchar();
  43.     getchar();
  44.     return 0;
  45. }

  46. /* in
  47. 9
  48. 2 3 5 8 9 10 18 26 32
  49. 6
  50. */
  51. /* out
  52. 2 3 5 6 8 9 10 18 26 32
  53. */

阅读(2058) | 评论(0) | 转发(0) |
0

上一篇:System Design

下一篇:20161019 ADV

给主人留下些什么吧!~~