24h購物| | PChome| 登入
2009-01-09 19:19:42| 人氣2,923| 回應0 | 上一篇 | 下一篇

反轉表

推薦 0 收藏 0 轉貼0 訂閱站台

由1開始之連續數字a1.a2.a3...an相對有一反轉表:b1.b2...bn。其bj代表意思為:數字j的位置前面有幾個比大個個數。-1做結束

範例輸入:

2 3 6 4 0 2 2 1 0

-1

說明:第一個2即為b1 代表1前面有2個比它大的數。

範例輸出:

5 9 1 8 2 6 4 7 3

/*************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
main()
{
 char input[1000];
 int output[1000],anstemp[1000];
 int a,b,c,temp,time,temp1,temp2;
 while(gets(input))
 {
  temp=0;temp1=0;temp2=0;time=0;
  if(input[0]=='-') break;
  for(a=0;a<=strlen(input);a++)
   {
    if(input[a]<=57&&input[a]>=48)
     temp=temp*10+input[a]-48;
    else
     {anstemp[time]=temp;temp=0;time++;}
     output[a]=-1;
   }
  for(a=0;a<time;a++)
   {
   temp1=anstemp[a]+1;temp2=0;
     for(b=0;b<time;b++)
      {
       if(output[b]==-1)
        temp2++;
       if(temp1==temp2)
        {
         output[b]=a+1;
         temp2=0;
         break;
        }
      }
   }
   for(a=0;a<time;a++)
    printf("%d ",output[a]);
    printf("\n");
  
 }
 return 0;     
}

台長: 來源不明
人氣(2,923) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 數位資訊(科技、網路、通訊、家電) | 個人分類: 資訊小題目 |
此分類下一篇:後序運算式

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文