724 - Reverse

All about problems in Volume 7. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
sml
New poster
Posts: 15
Joined: Mon Jul 24, 2006 3:34 pm

724 - Reverse

Post by sml » Mon Jul 31, 2006 2:04 am

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.

sml
New poster
Posts: 15
Joined: Mon Jul 24, 2006 3:34 pm

Post by sml » Mon Jul 31, 2006 2:49 am

It took me about 30 mins to make a quine, now just gotta reverse it. This is pretty easy. :)

Can't be judged?!? Damnit! That was the most elegant piece of code I've ever written!

sobhan naderi
New poster
Posts: 7
Joined: Sat Sep 02, 2006 8:59 am
Location: Sweden/Stockholm
Contact:

724(WA)

Post by sobhan naderi » Sat Sep 02, 2006 11:42 am

here is my C++ 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;
                }
        }
}
[/code]
Sobhan Naderi Parizi

Saswat2603
New poster
Posts: 15
Joined: Tue Feb 12, 2008 10:42 am
Location: Bhubaneswar, Orissa, India

724 - Reverse

Post by Saswat2603 » Sun Jan 04, 2009 3:55 pm

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 :-? :-? ?
Saswat Padhi - lost in for(;;);

User avatar
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Re: 724 - Reverse

Post by newton » Mon Jan 05, 2009 5:13 pm

May u submit ur code?

Saswat2603
New poster
Posts: 15
Joined: Tue Feb 12, 2008 10:42 am
Location: Bhubaneswar, Orissa, India

Re: 724 - Reverse

Post by Saswat2603 » Tue Jan 06, 2009 3:21 pm

Hi newton.

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/**/
The whole program is in a single line ! :wink:

I tried several minor modifications like printing the backward code in a new line. But still WA :x :-? :-? . HELP ME ..

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(;;);

User avatar
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Re: 724 - Reverse

Post by newton » Tue Jan 06, 2009 8:59 pm

Why in same line?

Saswat2603
New poster
Posts: 15
Joined: Tue Feb 12, 2008 10:42 am
Location: Bhubaneswar, Orissa, India

Re: 724 - Reverse

Post by Saswat2603 » Wed Jan 07, 2009 1:55 pm

@newton:

Because, I wanted the code 2 b shorter. :lol:

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. :x :x :x

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

So, I wrote the whole program in a single line !!

BTW, Is that the problem ????
Saswat Padhi - lost in for(;;);

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 724 - Reverse

Post by mf » Wed Jan 07, 2009 3:36 pm

Your program doesn't print a newline at the end of second copy, I think it should do so.

Saswat2603
New poster
Posts: 15
Joined: Tue Feb 12, 2008 10:42 am
Location: Bhubaneswar, Orissa, India

Re: 724 - Reverse

Post by Saswat2603 » Thu Jan 08, 2009 8:24 am

Here is the modified code ::

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/**/
But, still WA !!! Why ???? :x :x :x

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(;;);

Saswat2603
New poster
Posts: 15
Joined: Tue Feb 12, 2008 10:42 am
Location: Bhubaneswar, Orissa, India

Re: 724 - Reverse

Post by Saswat2603 » Tue Jan 13, 2009 2:25 pm

NO REPLY !?!?!?!?!?

Many have solved this quine thing.

Please some body help me find my mistake(s).
Saswat Padhi - lost in for(;;);

bleed1979
New poster
Posts: 8
Joined: Thu Oct 08, 2009 5:34 am

Is problem 724 able to judge??

Post by bleed1979 » Sat May 15, 2010 11:59 am

Is problem 724 able to judge??

Where we can find whether problems can judge or not ??

Thx for ur reply.

kissu parina
New poster
Posts: 19
Joined: Thu May 20, 2010 8:58 am

Re: 724 - Reverse

Post by kissu parina » Sun Feb 06, 2011 9:21 pm

Saswat2603 wrote:NO REPLY !?!?!?!?!?

Many have solved this quine thing.

Please some body help me find my mistake(s).
Hope fully you have solved it by now if not then read the problem specification carefully
happy coding
one day...

mszs
New poster
Posts: 4
Joined: Fri Jun 21, 2013 4:08 pm

Re: 724 - Reverse

Post by mszs » Fri Jun 21, 2013 4:17 pm

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.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 724 - Reverse

Post by brianfry713 » Sat Jun 22, 2013 6:43 am

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.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 7 (700-799)”