Submission #935986

#TimeUsernameProblemLanguageResultExecution timeMemory
935986sapientsapiensLozinke (COCI17_lozinke)C++14
40 / 100
88 ms856 KiB
#include <iostream>
#include <string>
#include <utility>

using namespace std;

int n;
string str[2005];
int ans = 0;

bool check(string a, string b) // checks if a is contained in b
{
    if(a.size() > b.size()) {
        swap(a, b);
    }
    for(int i = 0; i < b.size(); i++) {
        if(b[i] == a[0]) {
            bool c = true;
            for(int j = 0; j < a.size(); j++) {
                if(b[i + j] != a[j]){
                    c = false;
                    break;
                }
            }
            if(c) return true;
        }
    }
    return false;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> str[i];
    }
    for(int i = 0; i < n; i++) {
        for(int j = i+ 1; j < n; j++) {
            if(str[i] == str[j]) {
                ans += 2;
                continue;
            }
            if(check(str[i], str[j])) ans++;
            //test i on j
        }
    }
    cout << ans; 
    return 0;
}

Compilation message (stderr)

lozinke.cpp: In function 'bool check(std::string, std::string)':
lozinke.cpp:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i < b.size(); i++) {
      |                    ~~^~~~~~~~~~
lozinke.cpp:19:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |             for(int j = 0; j < a.size(); j++) {
      |                            ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...