Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

原来leading zero也要输出

Posted by Liuzhaoliang at 2014-08-18 13:28:54 on Problem 1023
唉唉矣
int main(){
    int t,k;
    long long n;
    char p[70];
    int repr[70],cnt;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&k);
        scanf("%s",p);
        scanf("%lld",&n);
        if(n==1LL<<63){
            n = -1;
            k-=63;
        }
        //printf("%lld\n",1ll<<63);
        if(n<0) {
            n = -n;
            for(int i=0;i<k;i++) if(p[i]=='p') p[i]='n';
            else p[i]='p';
        }
        cnt = 0;
        k--;
        bool failed = false;
        while(true){
            if(k<0) {
                break;
            }
            char c = p[k--];
            int d = n%2;
            n/=2;
            if(c=='p') repr[cnt++] = d;
            else{
                if(d==1) repr[cnt++] = d, n+=1;
                else repr[cnt++] = d;
            }
            //printf("(%d,%d)\n",d,n);
        }
        if(n) printf("Impossible\n");
        else{
            for(int i=cnt-1;i>=0;i--)printf("%d",repr[i]);
            printf("\n");
        }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator