← Back to topics
Topic

BubbleSecretary

D
Daniel93
Well the task seem in the first look easy, but I don't know what exactly I'm doing wrong. Maybe I don't understand the task clearly, but here is my code:

# include <iostream>
using namespace std;


char sheet[ 105 ][ 45 ];


int main(){

int n, m, diff, sol = 0, S1;
scanf("%d %d", &n, &m );

for(int i=0; i < n; i++ )
scanf("%s", sheet[i] );

for(int i=0; i < n; i++ ){

for(int j=0; j < n; j++ ){

if( i == j )continue;

diff = 0;
for(int p=0; p < m; p++ ){
if( sheet[ i ][ p ] != sheet[ j ][ p ] )diff++;
if( diff > 1 )break;
}

if( diff > 1 )break;
}

if( diff <= 1 ){ sol++; S1 = i; }
}


if( sol == 1 )printf("%s\n", sheet[S1] );
else if( sol > 1 )printf("AMBIGUOUS\n");
else printf("IMPOSSIBLE\n");

return 0;
}


Very simple brute force.
So can someone tell me what am I doing wrong. thx.
k
karakondzula
I am not sure for the code but example is wrong. Answer should be the sequence, wright?