Page 1 of 1

10978 - Let's Play Magic!

Posted: Fri Jul 21, 2006 11:54 pm
by shihabrc
Though its a quite easy simulation prob, I'm getting WA 4 this. Can any1 hlp ma(I/O,suggestions, anything).

Code: Select all

#include<stdio.h>
#include<string>
#include<string.h>

using namespace std;

#define MAX 52

int pos[MAX+1];
string card[MAX+1];
string placed[MAX+1];
bool flag[MAX+1];

void main()
{
	int N,i,j,k,current;
	char input[50];
	
//	freopen("C:\\4.txt","r",stdin);

	while(scanf("%d",&N)==1 && N)
	{
		getchar();
		
		for(i=1;i<=N;i++)
		{
			gets(input);
			card[i]=strtok(input," ");
			pos[i]=strlen(strtok(NULL," "));
			flag[i]=false;
		}
		
		current=0;

		for(i=1;i<=N;i++)
		{
			j=current;k=0;
			
			while(k<pos[i])
			{
				j++;
				if(j>N) j%=N;
				if(!flag[j]) k++;
				else continue;
			}

			current=j;

			placed[j]=card[i];
			flag[j]=true;

		}
	
		for(i=1;i<=N;i++)
		{
			if(i==1) printf("%s",placed[i].c_str());
			else printf(" %s",placed[i].c_str());
		}

		putchar('\n');
	}
}

Re: 10978 - Let's Play Magic!

Posted: Fri Apr 08, 2011 7:44 am
by DD
shihabrc wrote:Though its a quite easy simulation prob, I'm getting WA 4 this. Can any1 hlp ma(I/O,suggestions, anything).

Code: Select all

#include<stdio.h>
#include<string>
#include<string.h>

using namespace std;

#define MAX 52

int pos[MAX+1];
string card[MAX+1];
string placed[MAX+1];
bool flag[MAX+1];

void main()
{
	int N,i,j,k,current;
	char input[50];
	
//	freopen("C:\\4.txt","r",stdin);

	while(scanf("%d",&N)==1 && N)
	{
		getchar();
		
		for(i=1;i<=N;i++)
		{
			gets(input);
			card[i]=strtok(input," ");
			pos[i]=strlen(strtok(NULL," "));
			flag[i]=false;
		}
		
		current=0;

		for(i=1;i<=N;i++)
		{
			j=current;k=0;
			
			while(k<pos[i])
			{
				j++;
				if(j>N) j%=N;
				if(!flag[j]) k++;
				else continue;
			}

			current=j;

			placed[j]=card[i];
			flag[j]=true;

		}
	
		for(i=1;i<=N;i++)
		{
			if(i==1) printf("%s",placed[i].c_str());
			else printf(" %s",placed[i].c_str());
		}

		putchar('\n');
	}
}
I think there may be some problems between the transformation of char* and string. You may need to double-check that.

Re: 10978 - Let's Play Magic!

Posted: Tue May 27, 2014 7:25 am
by uDebug
Here's some input / output I found useful during testing / debugging.

Input

Code: Select all

13
AS ACE
2S TWO
3S THREE
4C FOUR
5C FIVE
6C SIX
7D SEVEN
8D EIGHT
9D NINE
TH TEN
JH JACK
QH QUEEN
KH KING
13
AS ACE
2S TWO
3S THREE
4C FOUR
5C FIVE
6C SIX
7D SEVEN
8D EIGHT
9D NINE
TH TEN
JH JACK
QH QUEEN
KH KING
52
AS ACE
2S TWO
3S THREE
4S FOUR
5S FIVE
6S SIX
7S SEVEN
8S EIGHT
9S NINE
TS TEN
JS JACK
QS QUEEN
KS KING
AC ACE
2C TWO
3C THREE
4C FOUR
5C FIVE
6C SIX
7C SEVEN
8C EIGHT
9C NINE
TC TEN
JC JACK
QC QUEEN
KC KING
AH ACE
2H TWO
3H THREE
4H FOUR
5H FIVE
6H SIX
7H SEVEN
8H EIGHT
9H NINE
TH TEN
JH JACK
QH QUEEN
KH KING
AD ACE
2D TWO
3D THREE
4D FOUR
5D FIVE
6D SIX
7D SEVEN
8D EIGHT
9D NINE
TD TEN
JD JACK
QD QUEEN
KD KING
0
AC Output:

Code: Select all

QH 4C AS 8D KH 2S 7D 5C TH JH 3S 6C 9D
QH 4C AS 8D KH 2S 7D 5C TH JH 3S 6C 9D
TH 8D AS AC 5H 2S JC 2C KD 2D 3S 6H JH 3C 4S QC 7D 5D 5S 4C TD 6S KC 7H 5C JD 7S AH 6C QH 3D 8S 2H 6D 7C 9S 8H 9D TS KH 3H 8C JS QD 9H 4D 9C QS 4H AD TC KS

Re: 10978 - Let's Play Magic!

Posted: Tue May 27, 2014 7:28 am
by uDebug
shihabrc wrote:Though its a quite easy simulation prob, I'm getting WA 4 this. Can any1 hlp ma(I/O,suggestions, anything).
Try "int main()" and "return 0;" instead of "void main().