关闭

UVA-213

46人阅读 评论(0) 收藏 举报
分类:

AOAPC上解题过程非常详细,运用好<<运算符能简化计算方式。
Solution:

#include <algorithm>
#include <iostream>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <deque>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <list>
using namespace std;
typedef long long LL;
typedef long long ll;
#define mm(a,i) memset(a, i, sizeof(a));
#define Mod 1000000007
#define SC_C(s)           scanf("%c", &s)
#define SC(a)             scanf("%d", &a)
#define SCC(a,b)          scanf("%d %d", &a, &b)
#define SCCC(a,b,c)       scanf("%d %d %d", &a, &b, &c)
#define FXA(i,a,n)        for(int i=a; i<n; i++)
#define FDA(i,a,n)        for(i=a; i>n; i++)
#define FXDA(i,a,n)       for(i=a; i<=n; i++)
#define FDDA(i,a,n)       for(i=a; i>=n; i++)
#define FXB(i,a,n)        for(i=a; i<n; i--)
#define FDB(i,a,n)        for(i=a; i>n; i--)
#define FXDB(i,a,n)       for(i=a; i<=n; i--)
#define FDDB(i,a,n)       for(i=a; i>=n; i--)
#define PF(n)             printf("%d\n", n);
#define PFF(n,m)          printf("%d %d\n", n, m);
#define PFFF(x,y,z)       printf("%d %d %d\n", x, y, z);
#define PF_Case(i)        printf("Case #%d:\n",i);
#define PF_C(i)           printf("%c:\n",i);
#define PF_L(x)           printf("%I64d\n",x);
#define IN                freopen("D:\\in.txt","r",stdin);
#define ENT               printf("\n");
#define MAX(a,b)          a>b?a:b
#define MIN(a,b)          a<b?a:b
const int INF = 0x3fffffff;
bool flag, flagg;
int cnt;
void in() {
#ifndef ONLINE_JUDGE
    IN;
#endif // ONLINE_JUDGE
}
int code[8][1<<8];

int readchar() {
    for( ; ; ) {
        int ch = getchar() ;
        if(ch!='\n')
            return ch;

    }
}

int readint(int c) {
    int v = 0;
    while(c--)
        v = v*2+readchar()-'0';
    return v;
}

int readcodes() {
    mm(code,0)
    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')
                return 1;
            code[len][i] = ch;
        }
    }
    return 1;
}

void printcodes() {
    for(int len=1; len<=7; 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]);
        }
    }
}
main() {
    in();
    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]);
            }
        }
        ENT
    }
    return 0;
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2227次
    • 积分:306
    • 等级:
    • 排名:千里之外
    • 原创:30篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档