170 - Clock Patience
Moderator: Board moderators
-
- New poster
- Posts: 4
- Joined: Sun Jan 06, 2002 2:00 am
-
- New poster
- Posts: 4
- Joined: Sun Jan 06, 2002 2:00 am
I forgot to mention that I'm using Java to solve this problem.
I downloaded from the web a C program that solves this problem (acknowledge by the online judge) and using extensive test cases both my Java program and this C program give the same results.
I think that the difference might be on the way input is passed to the program once is compiled by the online judge. (That's the disadvantage of using Java to solve these problems - well other than speed).
Any thoughts on this?
This problem seemed so simple...
Thank you very much for any help
I downloaded from the web a C program that solves this problem (acknowledge by the online judge) and using extensive test cases both my Java program and this C program give the same results.
I think that the difference might be on the way input is passed to the program once is compiled by the online judge. (That's the disadvantage of using Java to solve these problems - well other than speed).
Any thoughts on this?
This problem seemed so simple...
Thank you very much for any help
170 - Clock Patience
I know this is classic problem but i really have solve 170th problem but judge said to "wrong answer" .
? doubt from this sentence "The output will consist of one line per deck "
if there is one output , after the solution ,consist a '\n' or not or , there are multiple output , after last one , become a new line character '\n' or not or any other probability. Please help me [/c]
? doubt from this sentence "The output will consist of one line per deck "
if there is one output , after the solution ,consist a '\n' or not or , there are multiple output , after last one , become a new line character '\n' or not or any other probability. Please help me [/c]
from Turkiye
-
- Experienced poster
- Posts: 193
- Joined: Thu Sep 19, 2002 6:39 am
- Location: Indonesia
- Contact:
My AC-ed solution gave this kind of output:
44,KD
01,2S
So, it is really one output line per deck.
Before I submitted a solution I had this error when I didn't clear up some variables in one case, thus, it fails the next case ... not sure if you have the same problem as I did. I'm sure you tested more than one case ...
-turuthok-
44,KD
01,2S
So, it is really one output line per deck.
Before I submitted a solution I had this error when I didn't clear up some variables in one case, thus, it fails the next case ... not sure if you have the same problem as I did. I'm sure you tested more than one case ...
-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
-
- Experienced poster
- Posts: 187
- Joined: Wed Dec 11, 2002 2:03 pm
- Location: Mount Papandayan, Garut
170 Clock Patience
i want to ask, whether i misunderstood the problem or not. i've simulated the sample input, i got 51,KC, instead of 44,KD.
here is my code
[c]
#include <stdio.h>
#include <string.h>
#include <ctype.h>
typedef struct {
char angka, bentuk;
} tcard;
tcard stack[13][4], opencard;
int top[13], jumopen;
int convert (char x) {
int ret;
if (x >= '2' && x <= '9')
ret = x-'0'- 1;
else {
switch (x) {
case 'A' : ret = 0; break;
case 'T' : ret = 9; break;
case 'J' : ret = 10; break;
case 'Q' : ret = 11; break;
case 'K' : ret = 12; break;
}
}
return ret;
}
int main() {
char ch;
int jum, l, i;
while (1) {
ch = getchar();
while (!isalnum (ch) && ch != '#') ch = getchar();
if (ch == '#') break;
memset (top, 0, sizeof(int)*13);
jum = 0;
while (1) {
if (jum == 52) break;
if (isalnum (ch)) {
stack[jum%13][top[jum%13]].angka = ch;
ch = getchar();
stack[jum%13][top[jum%13]].bentuk = ch;
top[jum%13] = top[jum%13] + 1;
jum++;
}
ch = getchar();
}
opencard = stack[12][3]; top[12] = top[12] - 1;
l = convert (opencard.angka);
while (top[l] != 0) {
top[l] = top[l] - 1;
opencard = stack[l][top[l]];
l = convert (opencard.angka);
}
jumopen = 52;
for (i = 0; i < 13; i++)
jumopen -= top;
printf ("%2d,%c%c\n", jumopen, opencard.angka, opencard.bentuk);
}
return 0;
}
[/c]
here is my code
[c]
#include <stdio.h>
#include <string.h>
#include <ctype.h>
typedef struct {
char angka, bentuk;
} tcard;
tcard stack[13][4], opencard;
int top[13], jumopen;
int convert (char x) {
int ret;
if (x >= '2' && x <= '9')
ret = x-'0'- 1;
else {
switch (x) {
case 'A' : ret = 0; break;
case 'T' : ret = 9; break;
case 'J' : ret = 10; break;
case 'Q' : ret = 11; break;
case 'K' : ret = 12; break;
}
}
return ret;
}
int main() {
char ch;
int jum, l, i;
while (1) {
ch = getchar();
while (!isalnum (ch) && ch != '#') ch = getchar();
if (ch == '#') break;
memset (top, 0, sizeof(int)*13);
jum = 0;
while (1) {
if (jum == 52) break;
if (isalnum (ch)) {
stack[jum%13][top[jum%13]].angka = ch;
ch = getchar();
stack[jum%13][top[jum%13]].bentuk = ch;
top[jum%13] = top[jum%13] + 1;
jum++;
}
ch = getchar();
}
opencard = stack[12][3]; top[12] = top[12] - 1;
l = convert (opencard.angka);
while (top[l] != 0) {
top[l] = top[l] - 1;
opencard = stack[l][top[l]];
l = convert (opencard.angka);
}
jumopen = 52;
for (i = 0; i < 13; i++)
jumopen -= top;
printf ("%2d,%c%c\n", jumopen, opencard.angka, opencard.bentuk);
}
return 0;
}
[/c]
Kalo mau kaya, buat apa sekolah?
-
- Experienced poster
- Posts: 193
- Joined: Thu Sep 19, 2002 6:39 am
- Location: Indonesia
- Contact:
Hello titid, ... 51,KC seems very familiar to me ... it's all about this input description (especially the last sentence):
-turuthok-The input will consist of decks of cards arranged in four lines of 13 cards, cards separated by a single blank. Each card is represented by two characters, the first is the rank (A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K) followed by the suit (H, D, C, S). The input will be terminated by a line consisting of a single #. The deck is listed from bottom to top, so the first card dealt is the last card listed.
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).
-
- Experienced poster
- Posts: 187
- Joined: Wed Dec 11, 2002 2:03 pm
- Location: Mount Papandayan, Garut
-
- Experienced poster
- Posts: 187
- Joined: Wed Dec 11, 2002 2:03 pm
- Location: Mount Papandayan, Garut
here are cards open when playing game for given sample input
now i can see that the last card is KC, not KD as in given sample output. am i wrong?
Code: Select all
3C
AH
AS
6D
JC
QD
6C
JS
4C
6H
QS
6S
2D
7C
7D
8H
AC
9D
5C
KD
9C
8C
3D
9S
4H
5S
7S
TD
TC
3S
7H
3H
8S
2C
4S
JD
AD
TS
5H
2S
JH
TH
2H
QC
4D
8D
KH
5D
QH
KS
KC
Kalo mau kaya, buat apa sekolah?
-
- Experienced poster
- Posts: 192
- Joined: Sat Nov 30, 2002 5:14 am
Plz note what "dealt" mean......




7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
- szymcio2001
- New poster
- Posts: 38
- Joined: Mon Dec 09, 2002 1:53 pm
- Location: Poznan, Poland
Problem 170 TLE
I tried to solve problem 170 clock patience, and I have tested with 4 decks of cards in a single input file. My program gave the outputs for the 4 decks of cards fast. Is there any sample input that I could test with to find out why time limit exceeded? And how many decks of cards could there be in a single input file? I have also tested with a test case that actually plays out the whole deck and it works as well. What could be wrong? Can anyone help please?
Here is the sample input I tested with:
TS QC 8S 8D QH 2D 3H KH 9H 2H TH KS KC
9D JH 7H JD 2S QS TD 2C 4H 5H AD 4D 5D
6D 4S 9S 5S 7S JS 8H 3D 8C 3S 4C 6S 9C
AS 7C AH 6H KD JC 7D AC 5C TC QD 6C 3C
KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S AS
KH QH JH TH 9H 8H 7H 6H 5H 4H 3H 2H AH
KC QC JC TC 9C 8C 7C 6C 5C 4C 3C 2C AC
KD QD JD TD 9D 8D 7D 6D 5D 4D 3D 2D AD
3C 6C QD TC 5C AC 7D JC KD 6H AH 7C AS
9C 6S 4C 3S 8C 3D 8H JS 7S 5S 9S 4S 6D
5D 4D AD 5H 4H 2C TD QS 2S JD 7H JH 9D
KC KS TH 2H 9H KH 3H 2D QH 8D 8S QC TS
KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S AS
QH JH TH 9H 8H 7H 6H 5H 4H 3H 2H AH KH
JC TC 9C 8C 7C 6C 5C 4C 3C 2C AC KC QC
TD 9D 8D 7D 6D 5D 4D 3D 2D AD KD QD JD
#
And the outputs:
44,KD
04,KD
51,KC
52,KD
Here is the sample input I tested with:
TS QC 8S 8D QH 2D 3H KH 9H 2H TH KS KC
9D JH 7H JD 2S QS TD 2C 4H 5H AD 4D 5D
6D 4S 9S 5S 7S JS 8H 3D 8C 3S 4C 6S 9C
AS 7C AH 6H KD JC 7D AC 5C TC QD 6C 3C
KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S AS
KH QH JH TH 9H 8H 7H 6H 5H 4H 3H 2H AH
KC QC JC TC 9C 8C 7C 6C 5C 4C 3C 2C AC
KD QD JD TD 9D 8D 7D 6D 5D 4D 3D 2D AD
3C 6C QD TC 5C AC 7D JC KD 6H AH 7C AS
9C 6S 4C 3S 8C 3D 8H JS 7S 5S 9S 4S 6D
5D 4D AD 5H 4H 2C TD QS 2S JD 7H JH 9D
KC KS TH 2H 9H KH 3H 2D QH 8D 8S QC TS
KS QS JS TS 9S 8S 7S 6S 5S 4S 3S 2S AS
QH JH TH 9H 8H 7H 6H 5H 4H 3H 2H AH KH
JC TC 9C 8C 7C 6C 5C 4C 3C 2C AC KC QC
TD 9D 8D 7D 6D 5D 4D 3D 2D AD KD QD JD
#
And the outputs:
44,KD
04,KD
51,KC
52,KD