psbook solutions

সমস্যা ও সমাধান বই - ১ এর উপর অনুশীলন ( Practice code for Problem and Solutions Book - 1 by Mahbubul Hasan )

View the Project on GitHub

UVa 10815 - Andy’s First Dictionary

Python

Commit Time 15 Oct 2017 14:44

from sys import stdin
from re import split

text = stdin.read()
text = text.strip().lower()
words = set(split(r'[^a-z]', text))

for word in sorted(words):
    if(word):
        print(word)

C++

Commit Time 15 Oct 2017 14:44
#include <bits/stdc++.h>

using namespace std;

void clean(char line[]) {
    int i = 0;
    while(line[i] != '\0') {
        line[i] = tolower(line[i]);
        if(!isalpha(line[i])) line[i] = ' ';
        i++;
    }
}

int main() {
    ios::sync_with_stdio(false);
    char line[210];
    string w;
    set<string> dict;
    while(gets(line)) {
        clean(line);
        istringstream iS(line);
        while(iS>>w) {
            dict.insert(w);
        }
    }
    for(auto w: dict) {
        cout<<w<<endl;
    }
    return 0;
}