istringstream。PKU2493 Rdeaalbe。

囧。 同样的题目在PKU上过了。 HOJ上总是超时。。。

http://poj.org/problem?id=2493

istringstream 可将整行字符串由空格分开成一个个连续字符串。

代码如下:

#include<iostream>
#include
<sstream>
#include
<algorithm>
#include
<map>
#include
<cstdio>
using namespace std;

int main() {
int se;
cin
>> se;
for (int c = 1; c <= se; c++) {
cout
<< "Scenario #" << c << ":\n";
int n, m;
cin
>> n;
map
<string, int>ma;
string tmp;
while (n--) {
cin
>> tmp;
sort(tmp.begin()
+ 1, tmp.end() - 1);
ma[tmp]
++;
}
cin
>> m;
getchar();
while (m--) {
int sum = 1;
getline(cin, tmp);
istringstream
is(tmp);
string w;
while (is >> w) {
sort(w.begin()
+ 1, w.end() - 1);
sum
*= ma[w];
}
cout
<< sum << endl;
}
cout
<< endl;
}
return 0;
}

posted @ 2011-06-16 00:27  归雾  阅读(190)  评论(0)    收藏  举报