UVa 213 - Message Decoding

來源:互聯網
上載者:User

標籤:

將字元用01串進行編碼,並把下面的01串轉換成對應字串

打了一遍書上的範例程式..

讀取單個字元的函數來忽略分行符號還是很神奇的

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 char code[8][1<<8]; 6 char readchar(){ 7     while(1){ 8         char ch=getchar(); 9         if(ch!=‘\n‘&&ch!=‘\r‘) return ch;10     }11 }12 int readint(int c){13     int v=0;14     while(c--) v=v*2+readchar()-‘0‘;15     return v; 16 }17 int readcode(){18     memset(code,0,sizeof(code));19     code[1][0]=readchar();20     for(int len=2;len<=7;len++){21         for(int i=0;i<(1<<len)-1;i++){22             char ch=getchar();23             if(ch==EOF) return 0;24             if(ch==‘\n‘||ch==‘\r‘) return 1;25             code[len][i]=ch;26         }27     }28     return 1;29 }30 int main()31 {32     while(readcode()){33         while(1){34             int len=readint(3);35             if(!len) break;36             while(1){37                 int v=readint(len);38                 if(v==(1<<len)-1) break;39                 putchar(code[len][v]);40             }41         }42         puts("");43     }44 }45 /*46 TNM AEIOU47 001010110001148 101000100111011001149 1100050 $#**51 01000001011011000111001010052 */

 

UVa 213 - Message Decoding

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.