涨知识: UVA - 213 Message Decoding

来源:互联网 发布:怎样设计logo知乎 编辑:程序博客网 时间:2024/05/05 04:14

#include <map>#include<cstdlib>#include <cstdio>#include <string>#include <vector>#include <cstring>#include <fstream>#include <iostream>#include <algorithm>using namespace std;    #define LOCAL//UVa213 M Decodingint readchar(){    for(;;){        int ch=getchar();        //if(ch!='\n' && ch !='\r') return ch;        if(ch!='\n') return ch;    }}int readint(int c){    int v=0;    while(c--) v=v*2 + readchar()-'0';    return v;}int code[8][1<<8];int readcodes(){    memset(code,0,sizeof(code));    code[1][0]=readchar();    for(int len=2; len<=7; len++){        for(int i=0; i<(1<<len)-1; i++){            int ch=getchar();            if(ch==EOF) return 0;            //if(ch=='\n' || ch=='\r') return 1;            if(ch=='\n') return 1;            code[len][i] =ch;        }    }    return 1;}void printcodes(){    for(int len=1; len<8; len++)    for(int i=0; i<(1<<len)-1; i++){        if(code[len][i]==0) return;        printf("code[%d][%d] = %c\n",len,i,code[len][i]);    }}int main(){#ifdef LOCAL    freopen("in1.txt","r",stdin);#endif // LOCAL    while(readcodes()){        //printcodes();        for(;;){            int len=readint(3);            if(len==0) break;            //printf("len=%d\n",len);            for(;;){                int v=readint(len);                //printf("v=%d\n",v);                if(v==(1<<len)-1) break;                putchar(code[len][v]);            }//for        }//for        putchar('\n');    }//while    return 0;}

字符串的读写问题一直都是我的弱项···

月底重刷



0 0
原创粉丝点击