| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:实在看不出来代码哪里还有问题了,总是WA..........In Reply To:实在看不出来代码哪里还有问题了,总是WA.......... Posted by:buaaGG at 2009-12-21 21:34:28 > #include <cstdio>
> #include <iostream>
> using namespace std;
>
> int main(){
> int t, k, i;
> char s[65];
> long long n;
> bool possible;
> scanf("%d", &t);
> while (t--){
> scanf("%d", &k);
> scanf("%s", s);
> // scanf("%lld", &n);
> cin >> n;
> possible = 1;
> if (s[0] == 'p' && n < 0) possible = 0;
> if (s[0] == 'n' && n > 0) possible = 0;
> for (i = k-1; i >= 0; i--){
> if (n & (1LL << (k - i - 1))){
> if (s[i] == 'p') n -= (1LL << (k - i - 1));
> else n += (1LL << (k - i - 1));
> s[i] = '1';
> }
> else{
> s[i] = '0';
> }
> }
> if (n != 0) possible = 0;
> printf("%s\n", possible ? s : "Impossible");
> }
> }
>
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator