All about problems in Volume 113. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
-
saman_saadi
- New poster
- Posts: 31
- Joined: Sun Feb 25, 2007 6:33 pm
- Location: Tehran
Post
by saman_saadi » Mon Nov 12, 2007 11:41 am
but In my compiler I test below code and it was correct:
Code: Select all
scanf("%d", &n);
for (/*cin >> n*/; n--;)
{
cin.get(); //feeding new line character in scanf("%d", &n)
ch1 = cin.get();
ch2 = cin.get();
cout << (unsigned char)ch1 << (unsigned char)ch2 << endl;
}
or you can write:
Code: Select all
scanf("%d\n", &n);
for (/*cin >> n*/; n--;)
{
ch1 = cin.get();
ch2 = cin.get();
cout << (unsigned char)ch1 << (unsigned char)ch2 << endl;
cin.get(); //feeding new line character
}
-
Lomir
- New poster
- Posts: 19
- Joined: Mon Sep 17, 2007 10:05 pm
-
Contact:
Post
by Lomir » Mon Nov 12, 2007 11:52 am
char ch = 255;
ch is negative one !
but the clarification said that the character codes are non-negative.
"character value" In clarification means the amount of money paid for character. There is nothing said about character code. So codes may be in range of 0-225, and you must use usigned version of char.
Btw, there is no spaces, \t or \n as paid characters.
-
Hojjat jafary
- New poster
- Posts: 10
- Joined: Sun Sep 16, 2007 9:35 am
Post
by Hojjat jafary » Mon Nov 12, 2007 12:19 pm
Last edited by
Hojjat jafary on Mon Nov 12, 2007 12:25 pm, edited 1 time in total.
All Professionals was once an amateur.
-
hamedv
- Learning poster
- Posts: 98
- Joined: Mon May 07, 2007 8:30 am
Post
by hamedv » Mon Nov 12, 2007 12:20 pm
Last edited by
hamedv on Mon Nov 12, 2007 12:29 pm, edited 1 time in total.
-
saman_saadi
- New poster
- Posts: 31
- Joined: Sun Feb 25, 2007 6:33 pm
- Location: Tehran
Post
by saman_saadi » Mon Nov 12, 2007 12:22 pm
Strange, now I check the range of characters and it was [-128, 127]. Is it possible they correct the input?
-
hamedv
- Learning poster
- Posts: 98
- Joined: Mon May 07, 2007 8:30 am
Post
by hamedv » Mon Nov 12, 2007 12:25 pm
i got ac in contest and got ac after that
-
Leonid
- Experienced poster
- Posts: 146
- Joined: Thu Dec 22, 2005 5:50 pm
-
Contact:
Post
by Leonid » Mon Nov 12, 2007 12:45 pm
Solution for each test case must be printed on a separate line.
I.e.
Code:
10.10$
10.11$
Each character value is non-negative and at most 1000 cents worth.
That was ment to say, that character value IN CENTS is non-negative, but not character code

. Although character code is non-negative too (refer the following table:
http://www.asciitable.com/). But since you read it in "char", which has range -128 <= x < 128 then every character in input which has code greater or equal than 128 is converted to negative value and you get WA

-
RC's
- Learning poster
- Posts: 65
- Joined: Fri Jul 13, 2007 3:17 pm
Post
by RC's » Tue Nov 13, 2007 8:44 am
I used char but I get AC..
I think the problem is not because of that.
In the past I got WA because I use int for the cost, after I use unsigned long long to store the value before dividing it by 100, I got AC.
-
Darko
- Guru
- Posts: 580
- Joined: Fri Nov 11, 2005 9:34 am
- Location: Calgary, Canada
Post
by Darko » Tue Nov 13, 2007 9:11 am
Where did the input come from? Are you sure that the character values are in [0..255]?
The reason I am asking is because I had to increase the array sizes to get it to pass in Java. If the text was copied and pasted from somewhere, it probably contained Unicode characters.
-
Lomir
- New poster
- Posts: 19
- Joined: Mon Sep 17, 2007 10:05 pm
-
Contact:
Post
by Lomir » Tue Nov 13, 2007 2:20 pm
Yes, test input was copied. However it was resaved in ANSI encoding. So, I think that no characters higher then 255 have left.
I use gets() and vector of 255 elements.
If there was some unicode characters I think you sould get WA. Because my solution work only with char/usigned char [0..255].
-
saman_saadi
- New poster
- Posts: 31
- Joined: Sun Feb 25, 2007 6:33 pm
- Location: Tehran
Post
by saman_saadi » Tue Nov 13, 2007 2:50 pm
RC's wrote:I used char but I get AC..
I think the problem is not because of that.
In the past I got WA because I use int for the cost, after I use unsigned long long to store the value before dividing it by 100, I got AC.
I use char and got WA then I change char to unsigned char and got AC. One of my friends got AC using char. It's interesting that he use int for the cost not unsigned long long!
-
Lomir
- New poster
- Posts: 19
- Joined: Mon Sep 17, 2007 10:05 pm
-
Contact:
Post
by Lomir » Tue Nov 13, 2007 4:35 pm
int for total cost is enought. We are not so cruel

Maximum answer is: 1766189.55$.
Maybe you used C not C++? I do not know how it works in C.
As far as C++ unsinged char must be used. Overway you will index array out of boundary and this is UB.
-
sclo
- Guru
- Posts: 519
- Joined: Mon Jan 23, 2006 10:45 pm
- Location: Vancouver, BC, Canada
-
Contact:
Post
by sclo » Tue Nov 13, 2007 11:01 pm
I used C and char and got WA. I think the problem is that I should've gotten run-time error, but the judge did not catch it and gave WA instead. I used more than 10 submissions on this problem.
-
lovemagic
- Learning poster
- Posts: 52
- Joined: Thu Oct 02, 2003 11:38 am
Post
by lovemagic » Wed Nov 14, 2007 6:44 am
the scanf part with %c made the trouble....
Last edited by
lovemagic on Mon Nov 19, 2007 7:16 pm, edited 1 time in total.
khobaib
-
mohsincsedu
- Learning poster
- Posts: 63
- Joined: Tue Sep 20, 2005 12:31 am
- Location: Dhaka
-
Contact:
Post
by mohsincsedu » Wed Nov 14, 2007 7:04 am
Before post anything u must read the previous posts carefully....

Amra korbo joy akhdin............................