Submission #728183

# Submission time Handle Problem Language Result Execution time Memory
728183 2023-04-22T03:59:36 Z vjudge1 Zamjena (COCI18_zamjena) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define sts stable_sort
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define F first
#define S second
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define eb emplace_back
#define ll long long
#define ui unsigned int
#define ull unsigned long long

using namespace std;

const int MAXN = 1e6 + 4;
const int MOD = 1e9 + 7;
map<string, int> m;

int to_int(string s){
    int n = 0;

    for(int i = 0; i < s.size(); i++){
        n *= 10;
        n += s[i] - '0';
    }

    return n;
}

bool comp(string s){
    if(s[0] - '0' > 9){
        return 1;
    }
    return 0;
}

bool f(vector<string> &v, vector<string> &b, int &n){
    for(int i = 0; i < n; i++){
            if(comp(v[i]) && comp(b[i])){
                if(m[v[i]] == -1){
                    if(m[b[i]] != -1){
                        m[v[i]] = m[b[i]];
                    }
                }else if(m[b[i]] == -1){
                    if(m[v[i]] != -1){
                        m[b[i]] = m[v[i]];
                    }
                }else{
                    if(m[b[i]] != m[v[i]])return 0;
                }
            }else if(!comp(b[i])){
                if(m[v[i]] != -1){
                    if(m[v[i]] != to_int(b[i]))return 0;
                }
                m[v[i]] = to_int(b[i]);
            }else if(!comp(v[i])){
                if(m[b[i]] != -1){
                    if(m[b[i]] != to_int(v[i]))return 0;
                }
                m[b[i]] = to_int(v[i]);
            }else if(b[i] != v[i])return 0;
    }
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n; cin >> n;

    vector<string> v(n);
    vector<string> b(n);
    
    for(int i = 0; i < n; i++){
        cin >> v[i]; m[v[i]] = -1;
    }
    for(int i = 0; i < n; i++){
        cin >> b[i]; m[v[i]] = -1;
    }
    f(v, b, n);
    f(v, b, n);
    f(v, b, n);
    f(v, b, n);
    bool a = f(v, n);

    if(a){
        cout << "DA\n";
    }else{
        cout << "NE\n";
    }

    return 0;
}

Compilation message

zamjena.cpp: In function 'int to_int(std::string)':
zamjena.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
zamjena.cpp: In function 'int main()':
zamjena.cpp:90:19: error: invalid initialization of reference of type 'std::vector<std::__cxx11::basic_string<char> >&' from expression of type 'int'
   90 |     bool a = f(v, n);
      |                   ^
zamjena.cpp:42:43: note: in passing argument 2 of 'bool f(std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::__cxx11::basic_string<char> >&, int&)'
   42 | bool f(vector<string> &v, vector<string> &b, int &n){
      |                           ~~~~~~~~~~~~~~~~^