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

我的程序没考虑什么第64位,AC了

Posted by hakky at 2008-12-07 23:07:58 on Problem 1023
#include"iostream"
#include"stdio.h"
#include"algorithm"
using namespace std;
int main(){
	int m;
	cin>>m;
	while(m--){
		int n;
		cin>>n;
		int i;
		char c[65];
		cin>>c;
		int p[64];
		for(i=0;i<n;i++)
			if(c[i]=='p')
				p[i]=1;
			else p[i]=-1;
		long long a;
            scanf("%I64d",&a);
		reverse(c,c+n);
		reverse(p,p+n);
		int b[64];
		for(i=0;i<n;i++){
			if(abs(a)%2==1)
				b[i]=1;
			else b[i]=0;
			a=a-b[i]*p[i];
			a/=2;
		}
		if(a==0){
			for(i=n-1;i>=0;i--)
			   cout<<b[i];
		    cout<<endl;
		}
		else cout<<"Impossible\n";
	}
	system("pause");
	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