| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这题都有什么要注意的啊……谁能总结下?一直WA……或者帮看下我代码也行啊,thx~ ^_^
#include<string>
#include<map>
#include<iostream>
#include<algorithm>
#include<sstream>
#include<set>
using namespace std;
//ClearBuf 清空缓冲区函数,不用看……
inline void ClearBuf(istream& isIn)
{
streambuf *pSbThis;
char cTempBuf[20];
int iCount;
isIn.clear();
pSbThis=isIn.rdbuf();
iCount=pSbThis->in_avail();
while(iCount)
{
if(iCount>20)
{
pSbThis->sgetn(cTempBuf,20);
iCount-=20;
}
else
{
pSbThis->sgetn(cTempBuf,iCount);
iCount=0;
}
}
}
string SortMiddle(string word){
if(word.length()>3)
sort(word.begin()+1,word.end()-1);
return word;
}
int main(){
int scenarioNum;
cin>>scenarioNum;
for(int scenario=1;scenario<=scenarioNum;scenario++){
cout<<"Scenario #"<<scenario<<":"<<endl;
int dictionarySize;
cin>>dictionarySize;
map<string,int> dictionary;
set<string> accorded;
while(dictionarySize-->0){
string word;
cin>>word;
if(accorded.find(word)==accorded.end()){
dictionary[SortMiddle(word)]++;
accorded.insert(word);
}
}
int sentenceNum;
cin>>sentenceNum;
while(sentenceNum-->0){
string sentence;
ClearBuf(cin);
getline(cin,sentence);
istringstream buffer;
buffer.str(sentence);
string word;
int count=1;
while(buffer>>word){
if(dictionary.find(SortMiddle(word))==dictionary.end()){
count=0;
break;
}
count*=dictionary[SortMiddle(word)];
}
cout<<count<<endl;
}
cout<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator