724 - Reverse
Moderator: Board moderators
724 - Reverse
This looks like a fun one! I'm going to try my hand at it. Seems like a simple string storage problem. Should be easy as long as it's not expecting highly indented code.
-
- New poster
- Posts: 7
- Joined: Sat Sep 02, 2006 8:59 am
- Location: Sweden/Stockholm
- Contact:
724(WA)
here is my C++ code[/code]
Code: Select all
#include <iostream>
#include <string>
using namespace std;
struct rect{
int x, y;
}piece[2][15];
int n, p[2][15], turn, h, t;
void chugh(int a, int &lval, int val)
{
p[turn][a]=0;
lval=val;
turn=1-turn;
}
void dechugh(int a, int &lval, int val)
{
turn=1-turn;
lval=val;
p[turn][a]=1;
}
int back(int cnt)
{
//cerr<<turn<<"-"<<h<<t<<"---"<<p[0][0]<<p[0][1]<<","<<p[1][0]<<p[1][1]<<endl;
int ans[]={0, 0, 0, 0};
int winner[]={1, 1};
for(int i=0;i<n;i++)
{
winner[0]=winner[0]&&(!p[0][i]);
winner[1]=winner[1]&&(!p[1][i]);
}
if(winner[0])return 1;
if(winner[1])return 2;
for(int i=0;i<n;i++)
{
// cout<<"i="<<i<<endl;
if(p[turn][i])
{
if(piece[turn][i].x==h)
chugh(i, h, piece[turn][i].y), ans[back(0)]=1, dechugh(i, h, piece[turn][i].x);
if(piece[turn][i].x==t)
chugh(i, t, piece[turn][i].y), ans[back(0)]=1, dechugh(i, t, piece[turn][i].x);
if(piece[turn][i].y==h)
chugh(i, h, piece[turn][i].x), ans[back(0)]=1, dechugh(i, h, piece[turn][i].y);
if(piece[turn][i].y==t)
chugh(i, t, piece[turn][i].x), ans[back(0)]=1, dechugh(i, t, piece[turn][i].y);
}
if(ans[1]+2*ans[2]+3*ans[3]>=3)
return 3;
}
if(ans[1]+2*ans[2]+3*ans[3]==0)
{
turn=1-turn;
int result=(cnt)? 0: back(1);
turn=1-turn;
return result;
}
return ans[1]+2*ans[2]+3*ans[3];
}
int blank=0;
main()
{
while(cin>>n, n)
{
if(blank)cout<<endl;
blank=1;
for(int i=0;i<n;cin>>piece[0][i].x>>piece[0][i].y, i++);
for(int i=0;i<n;cin>>piece[1][i].x>>piece[1][i].y, i++);
h=-1;
int index;
for(int i=0;i<n;i++)
{
if(piece[0][i].x==piece[0][i].y && piece[0][i].x>h)
turn=1, h=piece[0][i].x, index=i;
if(piece[1][i].x==piece[1][i].y && piece[1][i].x>h)
turn=0, h=piece[1][i].x, index=i;
}
t=h;
for(int i=0;i<n;p[0][i]=p[1][i]=1, i++);
if(turn)p[0][index]=0;else p[1][index]=0;
switch(back(0))
{
case 0:
cout<<"No players can win"<<endl;
break;
case 1:
cout<<"Only player Red can win"<<endl;
break;
case 2:
cout<<"Only player Green can win"<<endl;
break;
default:
cout<<"Both players can win"<<endl;
}
}
}
Sobhan Naderi Parizi
-
- New poster
- Posts: 15
- Joined: Tue Feb 12, 2008 10:42 am
- Location: Bhubaneswar, Orissa, India
724 - Reverse
I tried making a palindromic ANSI C quine that prints itself twice and submitted it to the judge...But received a WA
.
Can anyone tell me why?
A palindromic quine fulfills all conditions stated --
--> The program prints itself first
--> Then, it prints itself again (for backward print)
Where did I go wrong
?

Can anyone tell me why?
A palindromic quine fulfills all conditions stated --
--> The program prints itself first
--> Then, it prints itself again (for backward print)
Where did I go wrong


Saswat Padhi - lost in for(;;);
-
- New poster
- Posts: 15
- Joined: Tue Feb 12, 2008 10:42 am
- Location: Bhubaneswar, Orissa, India
Re: 724 - Reverse
Hi newton.
Here is my source code ---
The whole program is in a single line ! 
I tried several minor modifications like printing the backward code in a new line. But still WA
. HELP ME ..
BTW, do you know how to retrieve the submitted source codes, I already posted in the Bugs/Suggestions section; but no reply.
Here is my source code ---
Code: Select all
/**/main(){char*a=/*/};0 nruter;)q,q,a,q,q,802+a(ftnirp;)01(rahctup;)q,q,a,q,q,802+a(ftnirp;'"'=q,/**/"/**/main(){char*a=/*/};0 nruter;)q,q,a,q,q,802+a(ftnirp;)01(rahctup;)q,q,a,q,q,802+a(ftnirp;'c%'=q,/**/c%s%c%/**/,q='c%';printf(a+208,q,q,a,q,q);putchar(10);printf(a+208,q,q,a,q,q);return 0;}/*/=a*rahc{)(niam/**/main(){char*a=/*/};0 nruter;)q,q,a,q,q,802+a(ftnirp;)01(rahctup;)q,q,a,q,q,802+a(ftnirp;'%c'=q,/**/%c%s%c/**/,q='%c';printf(a+208,q,q,a,q,q);putchar(10);printf(a+208,q,q,a,q,q);return 0;}/*/=a*rahc{)(niam/**/"/**/,q='"';printf(a+208,q,q,a,q,q);putchar(10);printf(a+208,q,q,a,q,q);return 0;}/*/=a*rahc{)(niam/**/

I tried several minor modifications like printing the backward code in a new line. But still WA



BTW, do you know how to retrieve the submitted source codes, I already posted in the Bugs/Suggestions section; but no reply.
Saswat Padhi - lost in for(;;);
-
- New poster
- Posts: 15
- Joined: Tue Feb 12, 2008 10:42 am
- Location: Bhubaneswar, Orissa, India
Re: 724 - Reverse
@newton:
Because, I wanted the code 2 b shorter.
When I make a new line in the source code,
I would have to reflect it in the output too.
And for that, I would have to add another 'putchar(10)' or puts("") or printf("\n").
As my code is a palindrome, I would have 2 add the reverse too.
I would have to reflect each SINGLE addition 4 TIMES in my code. (observe the code)
So, its a lot of pain.
I would have to change the printf commands too, 'cuz the position from where 2 start printing ( from the string 'a' )
So, I wrote the whole program in a single line !!
BTW, Is that the problem ????
Because, I wanted the code 2 b shorter.

When I make a new line in the source code,
I would have to reflect it in the output too.
And for that, I would have to add another 'putchar(10)' or puts("") or printf("\n").
As my code is a palindrome, I would have 2 add the reverse too.
I would have to reflect each SINGLE addition 4 TIMES in my code. (observe the code)
So, its a lot of pain.



I would have to change the printf commands too, 'cuz the position from where 2 start printing ( from the string 'a' )

So, I wrote the whole program in a single line !!
BTW, Is that the problem ????
Saswat Padhi - lost in for(;;);
Re: 724 - Reverse
Your program doesn't print a newline at the end of second copy, I think it should do so.
-
- New poster
- Posts: 15
- Joined: Tue Feb 12, 2008 10:42 am
- Location: Bhubaneswar, Orissa, India
Re: 724 - Reverse
Here is the modified code ::
But, still WA !!! Why ????
I'm sure it must be an issue with the new line or some other formatting, because my code IS a quine. I have checked it several times. It DOES PRINT itself.
Code: Select all
/**/main(){char*a=/*/};0 nruter;)01(rahctup;)q,q,a,q,q,232+a(ftnirp;)01(rahctup;)q,q,a,q,q,232+a(ftnirp;'"'=q,/**/"/**/main(){char*a=/*/};0 nruter;)01(rahctup;)q,q,a,q,q,232+a(ftnirp;)01(rahctup;)q,q,a,q,q,232+a(ftnirp;'c%'=q,/**/c%s%c%/**/,q='c%';printf(a+232,q,q,a,q,q);putchar(10);printf(a+232,q,q,a,q,q);putchar(10);return 0;}/*/=a*rahc{)(niam/**/main(){char*a=/*/};0 nruter;)01(rahctup;)q,q,a,q,q,232+a(ftnirp;)01(rahctup;)q,q,a,q,q,232+a(ftnirp;'%c'=q,/**/%c%s%c/**/,q='%c';printf(a+232,q,q,a,q,q);putchar(10);printf(a+232,q,q,a,q,q);putchar(10);return 0;}/*/=a*rahc{)(niam/**/"/**/,q='"';printf(a+232,q,q,a,q,q);putchar(10);printf(a+232,q,q,a,q,q);putchar(10);return 0;}/*/=a*rahc{)(niam/**/



I'm sure it must be an issue with the new line or some other formatting, because my code IS a quine. I have checked it several times. It DOES PRINT itself.
Saswat Padhi - lost in for(;;);
-
- New poster
- Posts: 15
- Joined: Tue Feb 12, 2008 10:42 am
- Location: Bhubaneswar, Orissa, India
Re: 724 - Reverse
NO REPLY !?!?!?!?!?
Many have solved this quine thing.
Please some body help me find my mistake(s).
Many have solved this quine thing.
Please some body help me find my mistake(s).
Saswat Padhi - lost in for(;;);
Is problem 724 able to judge??
Is problem 724 able to judge??
Where we can find whether problems can judge or not ??
Thx for ur reply.
Where we can find whether problems can judge or not ??
Thx for ur reply.
-
- New poster
- Posts: 19
- Joined: Thu May 20, 2010 8:58 am
Re: 724 - Reverse
Hope fully you have solved it by now if not then read the problem specification carefullySaswat2603 wrote:NO REPLY !?!?!?!?!?
Many have solved this quine thing.
Please some body help me find my mistake(s).
happy coding
one day...
Re: 724 - Reverse
1. Problem text is no longer found
2. I think I have a solution and I am suspecting a mistake in the accept/reject for this problem.
2. I think I have a solution and I am suspecting a mistake in the accept/reject for this problem.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 724 - Reverse
See:http://uva.onlinejudge.org/index.php?op ... category=9
724 has a red check, has no judge I/O, and you can't get AC.
724 has a red check, has no judge I/O, and you can't get AC.
Check input and AC output for thousands of problems on uDebug!