andy's-->>
andy
s
not andys.....

Moderator: Board moderators
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;
}
Code: Select all
class Main {
public static void main(String[] args) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line;
try {
Set<String> result = new HashSet<String>();
while ((line = reader.readLine()) != null) {
StringTokenizer tokenizer = new StringTokenizer(line, " !\"#$%&'()*+,-./0123456789:;<=>?@[]^_`{|}~");
while (tokenizer.hasMoreTokens()) {
result.add(tokenizer.nextToken().toLowerCase());
}
}
String[] words = result.toArray(new String[result.size()]);
Arrays.sort(words);
for (String word : words) {
System.out.println(word);
}
}
catch (IOException e) {
}
}
}
Code: Select all
AC
Code: Select all
a\bc
Code: Select all
a
bc
Ok, it seems like you try your best to pull out punctuation and sort that situation out. So with input like "help.me" you get help and me, but if you hit a word that's possessive, then you're screwed.Joarder wrote:Code: Select all
int main() { //freopen("10815 - Andy's First Dictionary_in.txt", "r", stdin); map<string,bool>m; map<string,bool>::iterator it; string str,str1; int l,i; while(cin>>str) { l=str.length(); str1.clear(); for(i=0;i<l;i++) { if((str[i]>='A' && str[i]<='Z') || (str[i]>='a' && str[i]<='z') || (str[i]>='0' && str[i]<='9')) { str[i]=tolower(str[i]); str1+=str[i]; } else { str.erase(i,1); i--; l--; if(!str1.empty()) { m[str1]=true; str1.clear(); } } } if(!str1.empty()) { m[str1]=true; str1.clear(); } } for(it=m.begin();it!=m.end();it++) cout<<(*it).first<<endl; return 0; }
Code: Select all
#include <set>
#include <string>
using std::set;
using std::string;
set<string> words;
Code: Select all
/* Removed */
Thanks guru (brianfry713).
I got AC