ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1089. Verification with the Dictionary

Grigory 'Stargazer' Javadyan [RAU] cpp ac code [2] // Problem 1089. Verification with the Dictionary 20 Oct 2008 16:02
#include <iostream>
#include <vector>
#include <string>
int corrections = 0;
bool words_match(const std::string& w1, const std::string& w2);
void process_word(const std::vector<std::string>& dict, const std::string& word);

int main(){
    std::vector<std::string> dictionary;
    std::string curr_dict_word;
    std::getline(std::cin, curr_dict_word);
    while(curr_dict_word != "#"){
        dictionary.push_back(curr_dict_word);
        std::getline(std::cin, curr_dict_word);
    }
    char c;
    std::string cword;
    while(std::cin.read(&c,1)){
        if('a'<=c && 'z'>=c){
            cword.insert(cword.end(), c);
            continue;
        }
        else if(!cword.empty()){
            process_word(dictionary, cword);
            cword = "";
        }
        std::cout << c;
    }
    if(!cword.empty()){
        process_word(dictionary, cword);
    }
    std::cout << corrections << std::endl;
    return 0;
}
bool words_match(const std::string& w1, const std::string& w2){
    if(w1.length() != w2.length()){
        return false;
    }
    bool mismatch = false;
    for(int i = 0; i < w1.length(); ++i){
        if(w1[i] != w2[i]){
            if(mismatch){
                return false;
            }
            mismatch = true;
        }
    }
    return mismatch;
}
void process_word(const std::vector<std::string>& dict, const std::string& word){
        for(int i = 0; i < dict.size(); ++i){
            if(words_match(dict[i], word)){
                std::cout << dict[i];
                ++corrections;
                return;
            }
        }
        std::cout << word;
}
Sinov No subject // Problem 1089. Verification with the Dictionary 9 Jul 2011 12:46
Please don't post your solution here.
esbybb Re: cpp ac code // Problem 1089. Verification with the Dictionary 23 Dec 2016 21:49
thanks mate