poj 1363 Rails

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   資料   for   

題目連結:http://poj.org/problem?id=1363

題目大意:1~n輸入,然後以題目要求進行輸出,判斷能否實現!“0”表示一組資料的結束~注意每組輸出後有一個空行!

 1 #include <iostream> 2 #include <cstdio> 3 #include <stack> 4 using namespace std; 5 int main () 6 { 7     int t,flag,s,n; 8     while (scanf("%d",&t)!=EOF) 9     {10         flag=0;11         if (t==0)12             break;13         while (1)14         {15             stack<int>q,qq;16             int ko=1;17             q.push(ko);18             for (int i=1; i<=t; i++)19             {20                 scanf ("%d",&n);21                 if (n==0)22                 {23                     flag=1;24                     break;25                 }26                 if (q.empty())27                 {28                     ko++;29                     q.push(ko);30                 }31                 int s=q.top();32                 while (s!=n)33                 {34                     if (ko==t)35                         break;36                     ko++;37                     q.push(ko);38                     s=q.top();39                 }40                 if (s==n)41                     q.pop();42             }43             if(flag)44                 break;45             if(q.empty())46                 puts("Yes");47             else48                 puts("No");49         }50         printf("\n");51     }52     return 0;53 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.