im getting a WA
this is my code :
- Code: Select all
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
using namespace std;
void parseLine(const string& line, set<string>& words);
string removePunctAndConvertToLowerCase(const string& word);
int main() {
string line;
set<string> words;
while (getline(cin, line))
if (line != "")
parseLine(line, words);
for (set<string>::iterator it = words.begin(); it != words.end(); it++)
cout << (*it) << endl;
return 0;
}
void parseLine(const string& line, set<string>& words) {
stringstream ss(stringstream::in | stringstream::out);
ss << line;
while (!ss.eof()) {
string word;
ss >> word;
word = removePunctAndConvertToLowerCase(word);
if (word != "" && words.find(word) == words.end())
words.insert(word);
}
}
string removePunctAndConvertToLowerCase(const string& word) {
string tmp;
for (int i = 0; i < (int) word.length(); i++) {
if (isalpha(word[i]))
tmp += tolower(word[i]);
}
return tmp;
}
General idea: i read a string containing one line, if that line is not empty, then ( parseLine ) parses it to words using string streams, removes punctuation and converts to lower case form and then check if it is not listed before
I would be very thankful if some one helped
