Larry wrote:Where t is the name of the map, and a is the name of the char array.
t[ string( a ) ] = whatever;
(Though, of course, it takes time..)
I used STL's map and got AC in about 5 secs..
Who did you read char arrays? gets()?
Moderator: Board moderators
Larry wrote:Where t is the name of the map, and a is the name of the char array.
t[ string( a ) ] = whatever;
(Though, of course, it takes time..)
I used STL's map and got AC in about 5 secs..
minskcity wrote:Larry wrote:Where t is the name of the map, and a is the name of the char array.
t[ string( a ) ] = whatever;
(Though, of course, it takes time..)
I used STL's map and got AC in about 5 secs..
Who did you read char arrays? gets()?
char y[size];
cin>>y;
set<char *> t;
t[y]=...;
char a[MAX_L];
map<string, int> t;
while ( gets( a ) ) {
t[ string( a ) ]++;
}
THANKS A LOT!!!!Larry wrote:I don't have the code in front of me, but I almost never use cin, (since I am still mostly a C programmer)
I do something like this:
- Code: Select all
char a[MAX_L];
map<string, int> t;
while ( gets( a ) ) {
t[ string( a ) ]++;
}
Of course, you have to clear and stuff, but that's how I handle it..
Larry wrote:I don't know, I use printf instead of cout, but otherwise, everything looks the same..
I use .clear() instead of reallocating the memory.. don't know which is faster..
[] is different from .find in that if the key is not in the map, it'll create it, while in .find, it'll just return 0. In this case, since that's what we want to do anyhow, I used []..
minskcity wrote:Your last code results in WA because it always prints 0.0000. (at least for me)
cout is fast enough for this problem: I've just moved to second place with 0.8sec, still using cout for output...
Users browsing this forum: No registered users and 1 guest