Created
January 16, 2015 08:58
-
-
Save kenornotes/a2852e26782bd348ffa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int match(int x, char s[]) { | |
int i = strlen(s)-1; | |
for ( ; i >= 0; i-- ) { | |
if ( s[i] == '?' ) { | |
x /= 10; | |
continue; | |
} | |
if ( s[i] - '0' != x % 10 ) return 0; | |
x /= 10; | |
} | |
return 1; | |
} | |
int main() { | |
char a[3][20]; | |
scanf("%s %s %s", &a[0], &a[1], &a[2]); | |
int length[3] = {strlen(a[0]), strlen(a[1]), strlen(a[2])}; | |
int min[3], max[3]; | |
int i, j, k, digit; | |
for ( i = 0; i < 3; i++ ) { | |
min[i] = max[i] = 0; | |
} | |
for ( j = 0; j < 2; j++ ) { | |
digit = 1; | |
for ( i = length[j]-1; i >= 0; i-- ) { | |
if ( a[j][i] == '?' ) { | |
min[j] += (0 * digit); | |
max[j] += (9 * digit); | |
} else { | |
min[j] += (a[j][i] - '0') * digit; | |
max[j] += (a[j][i] - '0') * digit; | |
} | |
digit *= 10; | |
} | |
} | |
for ( i = min[0]; i <= max[0]; i++ ) { | |
for ( j = min[1]; j <= max[1]; j++ ) { | |
if ( match( i, a[0] ) && match( j, a[1] ) && match( i+j, a[2] ) ) | |
printf( "%d + %d = %d\n", i, j, i+j ); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment