Last active
November 6, 2017 15:18
-
-
Save DNAlchemist/84366305b1d82cb5783ed3f70f8910fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <stdlib.h> | |
void bad_input() { | |
printf("bad input\n"); | |
exit(1); | |
} | |
int toint(char n) { | |
if(n == '0') return 0; | |
if(n == '1') return 1; | |
if(n == '2') return 2; | |
if(n == '3') return 3; | |
if(n == '4') return 4; | |
if(n == '5') return 5; | |
if(n == '6') return 6; | |
if(n == '7') return 7; | |
if(n == '8') return 8; | |
if(n == '9') return 9; | |
if(n == 'A') return 10; | |
if(n == 'B') return 11; | |
if(n == 'C') return 12; | |
if(n == 'D') return 13; | |
if(n == 'E') return 14; | |
if(n == 'F') return 15; | |
return -1; | |
} | |
int ne_cifra_po_osnovaniy_b1(char n) { | |
int value = toint(n); | |
if(value == -1) { | |
return 1; | |
} | |
return 0; | |
} | |
int znach_cifri_po_osnovaniy_b1(char n) { | |
return 'F'; | |
} | |
int main() | |
{ | |
int b1, b2; | |
char num[13]; | |
scanf("%d %d", &b1, &b2); | |
scanf("%s", num); | |
if (b1 < 2 || b1 > 16) { | |
printf("bad input\n"); | |
exit(1); | |
} | |
if (b2 < 2 || 16 < b2) { | |
printf("bad input\n"); | |
exit(1); | |
} | |
printf("b1=%d b2=%d num=%s \n", b1, b2, num); | |
//запускается норм | |
int x1, x2, b1n, j; | |
for (j = 0, x1 = 0; num[j]; ++j) { | |
if (num[j] == '.') { | |
++j; | |
break; | |
} | |
printf("1"); | |
if (ne_cifra_po_osnovaniy_b1(num[j])) { | |
bad_input(); | |
} | |
x1 = x1 * b1 + znach_cifri_po_osnovaniy_b1(num[j]); | |
} | |
for (x2 = 0, b1n = b1; num[j]; ++j) { | |
x2 = x2 * b1 + znach_cifri_po_osnovaniy_b1(num[j]); | |
b1n = b1n * b1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment