CSES - Putka Open 2015 – finaali - Results
Submission details
Task:Sanat
Sender:
Submission time:2015-12-20 17:13:49 +0200
Language:C++
Status:READY
Result:68
Feedback
groupverdictscore
#1ACCEPTED68
Test results
testverdicttimescore
#1ACCEPTED0.19 s68details

Compiler report

input/code.cpp: In function 'std::string classify(std::string&)':
input/code.cpp:42:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(s.size() >= 5 && nVowel >= s.size()/2) return finnish;
                                ^
input/code.cpp:44:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < s.size()-1; i++){
                      ^
input/code.cpp:51:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < s.size()-2; i++){
                      ^

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <sstream>
#include <fstream>
#include <cassert>

typedef long long LL;
using namespace std;

string foreign = "zxcbfqwg";
string vowel = "aeiuo";
string finnish = "10-4";
string english = "QAQ";

set<string> english_database;

bool is_foreign(char c){
    for(char f : foreign) if(c == f) return true;
    return false;
}

bool is_vowel(char c){
    for(char f : vowel) if(c == f) return true;
    return false;
}

string classify(string& s){
    if(english_database.count(s)){
        return english;
    }
    LL nVowel = 0;
    for(char c : s){
        if(c > 'z') return finnish;
        if(is_foreign(c)) return english;
        
        if(is_vowel(c)) nVowel++;
    }
    
    if(s.size() >= 5 && nVowel >= s.size()/2) return finnish;
    
    for(int i = 0; i < s.size()-1; i++){
        if(s[i] == s[i+1]) return finnish;
    }
    
    if(s.size() >= 2 && !is_vowel(s[s.size()-1]) && !is_vowel(s[s.size()-2]))
        return english;      
    
    for(int i = 0; i < s.size()-2; i++){
        if(!is_vowel(s[i]) && !is_vowel(s[i+1]) && !is_vowel(s[i+2])) return english;
    }

    return finnish;
}

int main(){
    
    ifstream dictionary("/etc/dictionaries-common/words");
    string word;
    while(dictionary >> word){
        string word2;
        for(auto c : word)
            if(tolower(c) >= 'a' && tolower(c) <= 'z')
                word2 += tolower(c);
            
        english_database.insert(word2);
    }
        
    LL n; cin >> n;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        cout << classify(s) << "\n";
    }
}


Test details

Test 1

Verdict: ACCEPTED

input
95000
pursua
zoomata
mantelilastu
jamming
...

correct output
10-4
10-4
10-4
QAQ
QAQ
...

user output
10-4
QAQ
10-4
QAQ
10-4
...