10226 - Hardwood Species
Moderator: Board moderators
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
Because streams (and esp. iomanip) were implemented in a different way in old version of g++. The flags were integers, so cout << an_ios_flag simply prints (and printed) an integer. That's why setf function is necessary to set a flag.
This was changed so that flags have their own class now (std::ios_base). operator<<, overloaded for this type, calls setf.
Flags like std::ios::right (which is equal 128 in g++ 3.3), for compatibility, are still integers. However, std::right is a std::ios_base object and can be passed as argument to operator<<.
This was changed so that flags have their own class now (std::ios_base). operator<<, overloaded for this type, calls setf.
Flags like std::ios::right (which is equal 128 in g++ 3.3), for compatibility, are still integers. However, std::right is a std::ios_base object and can be passed as argument to operator<<.
hm, actually it was std::cout << std::right which caused the error message in the first place.
or did I misinterpret your response 
Hagen.
Code: Select all
02603660_24.c: In function `int main()':
02603660_24.c:127: `::right' undeclared (first use here)

Hagen.
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
-
- Learning poster
- Posts: 95
- Joined: Mon Apr 26, 2004 1:23 pm
- Location: Hong Kong and United States
- Contact:
I used STL hash_map
But dunno why
I still got TLE...
can anybody help me?
[cpp]#include <hash_set.h>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
using namespace std;
int main()
{
int p;
cin>>p;
char h[32];
cin.getline(h,32);
cin.getline(h,32);
for (int y=0;y<p;y++)
{
if (y)
cout<<endl;
hash_multiset <char*> sky;
cin.getline(h,32);
while (strlen(h))
{
sky.insert(h);
cin.getline(h,32);
cout<<h<<endl;
cout<<sky.count(h)<<endl;
}
double i=sky.size()/100.0;
string s="";
cout<<i<<endl;
copy(sky.begin(), sky.end(), ostream_iterator<char*>(cout, " "));
for (hash_multiset <char*>::iterator l=sky.begin();l!=sky.end();l++)
{
if (*l!=s)
cout<<(*l)<<' '<<setprecision(4)<<setiosflags(ios::fixed)<<sky.count(*l)/i<<endl;
s=*l;
}
}
return 0;
} [/cpp]
But dunno why
I still got TLE...

can anybody help me?
[cpp]#include <hash_set.h>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
using namespace std;
int main()
{
int p;
cin>>p;
char h[32];
cin.getline(h,32);
cin.getline(h,32);
for (int y=0;y<p;y++)
{
if (y)
cout<<endl;
hash_multiset <char*> sky;
cin.getline(h,32);
while (strlen(h))
{
sky.insert(h);
cin.getline(h,32);
cout<<h<<endl;
cout<<sky.count(h)<<endl;
}
double i=sky.size()/100.0;
string s="";
cout<<i<<endl;
copy(sky.begin(), sky.end(), ostream_iterator<char*>(cout, " "));
for (hash_multiset <char*>::iterator l=sky.begin();l!=sky.end();l++)
{
if (*l!=s)
cout<<(*l)<<' '<<setprecision(4)<<setiosflags(ios::fixed)<<sky.count(*l)/i<<endl;
s=*l;
}
}
return 0;
} [/cpp]
First I used STL map - TLE.
Then I implemented my own hash, which made my program ran in linear time - TLE.
I changed my code to process only first 3 inputs - WA in 8.5 sec...
Then I sent:
[cpp]string s;
while(getline(cin, s));[/cpp] - TLE !!!!!????
I guess this is input problem, not algorithmic problem...
Then I implemented my own hash, which made my program ran in linear time - TLE.
I changed my code to process only first 3 inputs - WA in 8.5 sec...
Then I sent:
[cpp]string s;
while(getline(cin, s));[/cpp] - TLE !!!!!????
I guess this is input problem, not algorithmic problem...

-
- Learning poster
- Posts: 95
- Joined: Mon Apr 26, 2004 1:23 pm
- Location: Hong Kong and United States
- Contact:
yeaminskcity wrote:Who did you read char arrays? gets()?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..
i used sth like this:
char y[size];
cin>>y;
set<char *> t;
t[y]=...;
but when i call t.count(y) it is always 0
my code is shown above
the hash set throw away all data
Impossible is Nothing.
1) STL "set" is not hashset, optional second parameter in the template is comparator.char y[size];
cin>>y;
set<char *> t;
t[y]=...;
2) STL "set" does not look to support []. STL "map" does.
3) cin >> y will only read until space.
4) set < char * > might create a set of pointers, not strings.
---- According to Larry, it's possible to get AC by using STL map ( not hashed ) by reading char* and converting them into strings when accessing the map.
I was asking Larry which function he was using to read char arrays fast enough...
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
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:
Of course, you have to clear and stuff, but that's how I handle it..
I do something like this:
Code: Select all
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:Of course, you have to clear and stuff, but that's how I handle it..Code: Select all
char a[MAX_L]; map<string, int> t; while ( gets( a ) ) { t[ string( a ) ]++; }

The only change I made to my program was getline->gets...
That corresponded to 10+sec->1.77sec, AC, 7th in ranking... (looks like my hashing works)
PS: You might be a mostly a C programmer, but I bet you are using STL map whenever is possible.
