hi,
The following modification of your code compiles under g++ cygwin. You made some mistakes. Try looking at the changes. The OJ uses differnent compiler which is obviously better than VC++6.0. Try the dev-cpp which is a windows port of gcc. You can find it at
http://www.sourceforge.net.
[cpp]
#include <cstdio>
#include <iostream>
#include <vector>
#include <cctype>
#include <functional>
#include <algorithm>
using namespace std;
char *strUpper(char *);
char *getToken(char *);
class Word{
public:
char word[12];
vector<int> lst;
Word(char *str)
{
strcpy(word, strUpper(str));
lst.clear();
}
};
class Compare:binary_function<Word, Word, bool>{
public:
result_type operator()(first_argument_type A, second_argument_type B)
{
return (result_type)(!(strcmp(A.word, B.word) > 0));
}
};
char str[10000000L];
int main()
{
int set = 0, lnum;
char *p;
vector<Word> listOfWords;
vector<Word>::iterator iter;
vector<int>::iterator i;
while(gets(str)!=0){
if(str[0] == 0)
break;
if(!listOfWords.empty())
listOfWords.clear();
while(str[0]){
Word toPush(str);
listOfWords.push_back(toPush);
gets(str);
}
sort(listOfWords.begin(), listOfWords.end(), Compare());
gets(str);
for(lnum = 1; str[0]; lnum++){
strUpper(str);
p = getToken(str);
while(p){
iter = listOfWords.begin();
while(iter != listOfWords.end()){
int cmp = strcmp(p, iter->word);
if(cmp == 0){
iter->lst.push_back(lnum);
break;
}
else if(cmp < 0)
break;
iter++;
}
p = getToken(NULL);
}
gets(str);
}
cout << "Case " << ++set << endl;
for(iter = listOfWords.begin(); iter != listOfWords.end(); iter++){
if(!iter->lst.empty()){
i = iter->lst.begin();
cout << iter->word << " " << *i++;
bool seq;
for(seq = false; i != iter->lst.end(); i++){
switch(*i - *(i - 1)){
case 0:
break;
case 1:
seq = true;
break;
default:
if(seq){
cout << "-" << *(i - 1) << ", " << *i;
seq = false;
}
else
cout << ", " << *i;
break;
}
}
if(seq)
cout << "-" << *(i - 1);
cout << endl;
iter->lst.clear();
}
}
cout << endl;
}
return 0;
}
char *strUpper(char *in)
{
char *p = in;
while(*p){
*p = toupper(*p);
p++;
}
return in;
}
char *getToken(char *str)
{
static char *p;
char *q;
if(str)
p = str;
if(p == NULL)
return NULL;
while(!(isdigit(*p) || isalpha(*p)) && *p)
p++;
q = p;
while(isdigit(*p) || isalpha(*p))
p++;
if(*p == 0)
p = 0;
else
*p++ = 0;
return q;
}
[/cpp]
Good luck.
- Suman