this is my code in the contest?
I'm aware of space char and the final value too.
and got the res in long long.
I'm completely confused...
Code: Select all
woooooowh
what a great trick.
Got acc after that.
Thanks alot
Moderator: Board moderators
Code: Select all
woooooowh
what a great trick.
Got acc after that.
Thanks alot
Code: Select all
thanx all, got AC
According to rio's statement:armansuleimenov wrote:I used stl map, got TLE, now switched to simple hash table, got WA 3 times. what is wrong with my code?
Then you can't use string because:rio wrote: Finally figured out the trick after 20 few submissions..
Character code has range 0 ~ 255, so use unsigned char.
so each element of string is char (not unsigned char) and you must handle this.typedef basic_string<char> string;
What input routine should I use then?so each element of string is char (not unsigned char) and you must handle this.
Code: Select all
ll cost;
unsigned char ch;
cin>>ch>>cost;
cnt[(int)ch]=cost;
In the contest time they release a clarification:baodog wrote:Yes, you can read in char !! It just may be negative.
Simply add a constant !!! (128 or bigger)
Please, remove your code as good etiquette if you get ac.
According to the clarification character value is non-negative but I didn't see any statement about the range of characters in the problem. I got AC with unsigned char and don't handle negative characters. Are you sure there are negative characters in the input? If input has negative characters and the range of characters is -128 <= x <= 127 then I got AC in the contest time! After the contest I only change char to unsigned char (according to rio's statement) and got AC.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.
You say we must add a value 128 or higher to char so we have:-128 <= x <= 127
It's obvious 255 can't fit on char and it fit on unsigned char.[/code]0 <= x + 128 <= 255
You can use cin.get() method:armansuleimenov wrote: What input routine should I use then?
I can't use the code below since the character can be whitespace (' '):
Code: Select all
unsigned char ch = cin.get();
Code: Select all
scanf("%d\n",&m);
long total = 0;
while(m--){
unsigned char ch;
ch = cin.get();
cout << ch;
int cht = (int) ch;
}
I think you must use cin instead of scanf because cin buffer and scanf buffer are different.darkos32 wrote:how to used cin.get() ?
i used like this for input :
2
av
sd
but it prints nothing..and how to check the newline ?Code: Select all
scanf("%d\n",&m); long total = 0; while(m--){ unsigned char ch; ch = cin.get(); cout << ch; int cht = (int) ch; }
thanks.
Code: Select all
int n, ch1, ch2;
for (cin >> n; n--;)
{
cin.get(); //feeding new line character in cin >> n
ch1 = cin.get();
ch2 = cin.get();
cout << (unsigned char)ch1 << (unsigned char)ch2 << endl;
}
Code: Select all
ch = cin.get();
if (ch == '\n')
{
.
.
.
}
Code: Select all
if (ch == '\n' || ch == '\r')