Getting WA for UVa 1592 Database

Правка en3, от sjsakib, 2017-09-24 08:31:25

Update: With the same logic got accepted with python 3. So the problem is C++ specific. Please help me find the fault.

I was trying to solve UVa-1592-Database here's my code:

# include <bits/stdc++.h>

using namespace std;

string db[10007][12];
char buff[85];
int n,m;

bool read() {
    if(scanf("%d %d\n", &n,  &m) == EOF) return false;
    for (int i = 0; i < n; i++) {
        gets(buff); 
        int j=0,k=0;
        while(buff[j] != '\0') {
            if(buff[j] != ',') {
                db[i][k].push_back(buff[j]);
            } else k++;
            j++;
        }
    }
}

bool findDup(int c1, int c2) {
    map<pair<string, string>, int> mp;
    for (int r = 0; r < n; r++) {
        pair<string, string> p = make_pair(db[r][c1], db[r][c2]);
        //cout<<r<<' '<<db[r][c1]<<' '<<db[r][c2]<<endl;
        if(mp.find(p) == mp.end()) mp[p] = r;
        else {
            printf("NO\n%d %d\n%d %d\n", mp[p]+1, r+1, c1+1, c2+1);
            return true;
        }
    }
    return false;
}

void clear() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            db[i][j].clear();
        }
    }
}

int main() {
    while(read()) {
        bool found = false;
        for (int i = 0; i < m; i++) {
            for (int j = i+1; j < m; j++) {
                found = findDup(i,j);
                if(found) break;
            }
            if(found) break;
        }
        if(!found) printf("YES\n");
        clear();
    }
    return 0;
}
Python Code

Why am I getting WA? Can someone help with fresh eyes please? It passes the tests given in uDebug. Thanks

Теги uva, uva 1592, wronganswer, udebug, c++, c++11

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский sjsakib 2017-09-24 08:31:25 20
en2 Английский sjsakib 2017-09-24 08:26:26 1001
en1 Английский sjsakib 2017-09-24 07:47:00 1697 Initial revision (published)