HDU 4144 Bacon's Cipher (解码)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=4144

代码:

#include<stdio.h>
#include<string.h>

using namespace std;

int main()
{
    int a;
    while(~scanf("%d",&a)){
    if(a==0){
        printf("\n");return 0;}
    char b[10005];
    scanf("%s",b);
    //printf("%s",b);
    for(int i=0;i<a;i=i+5)
    {
        int num[5];
        memset(num,0,sizeof(num));
        num[0]=(b[i]>='0'&&b[i]<='9'?1:0);
        num[1]=(b[i+1]>='0'&&b[i+1]<='9'?1:0);
        num[2]=(b[i+2]>='0'&&b[i+2]<='9'?1:0);
        num[3]=(b[i+3]>='0'&&b[i+3]<='9'?1:0);
        num[4]=(b[i+4]>='0'&&b[i+4]<='9'?1:0);
        int ans=0,temp=1;
        for(int j=4;j>=0;j--)
        {
            if(num[j]==1)
                ans=ans+temp;
            temp=temp*2;
        }
        //printf("%d %d %d %d %d\n",num[0],num[1],num[2],num[3],num[4]);
        //printf("%d\n",ans);
        printf("%c",(char)'A'+ans);
    }
    printf("\n");}
}


也没说多组数据输入呀。

你可能感兴趣的:(HDU 4144 Bacon's Cipher (解码))