|
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
char Num_Str1[10];
char Num_Str2[10];
char Num_Str3[10];
int Num1=0, Num2=0, Num3=0;
int Mapping[10];
/* Store the mapping of A at location 0;
Store the mapping of B at location 1; ...
Store the mapping of J at location 9
For example, if we have the following mapping:
A->5, B->6, C->7, D->4, E->3, F->0, G->2, H->1, I->9, J->8
the elements of Mapping[] will be
{5, 6, 7, 4, 3, 0, 2, 1, 9, 8}
*/
int First_Map, Second_Map, num_map=1;
void read_equation(void);
void read_mapping(void);
void convert_all(void);
void try_try(void);
void show(void);
int main(void)
{
//freopen("input", "r",stdin);
read_equation();
read_mapping();
try_try();
show();
return 0;
}
void read_equation(void)
{
char cur_ch, str[10];
int i, len=0;
while(cur_ch=getchar()){
if(cur_ch=='+'){
for(i=0; i<len; i++){
Num_Str1[i] = str[i];
}
Num_Str1[i] = '\0'; len=0;
}
else if(cur_ch=='='){
for(i=0; i<len; i++){
Num_Str2[i] = str[i];
}
Num_Str2[i] = '\0'; len=0;
}
else if(cur_ch=='\n'){
for(i=0; i<len; i++){
Num_Str3[i] = str[i];
}
Num_Str3[i] = '\0'; len=0;
break;
}
else{
str[len] = cur_ch;
len++;
}
}
}
void read_mapping(void)
{
// Hint: refer to HW3b and modify by yourself
}
/*
Convert the encrypted numbers into the corresponding values (decimal numbers).
Store the results in the global variables Num1, Num2, Num3.
For example, if the elements of Mapping[] are
5 6 7 4 -1 -1 -1 -1 -1 3
and the elements of the three character arrays are
Num_Str1: 'A','B','C','\0'
Num_Str2: 'C','B','\0'
Num_Str3: 'B','D','J','\0'
then, the results of Num1, Num2, and Num3 should be 567, 76, and 643.
*/
void convert_all(void)
{
/*
Hint:
Check the characters stored in Num_Str1.
Use Mapping[] to find the corresponding values and store the results
in Num1, Num2, and Num3.
*/
}
/*
Show
*/
void show(void)
{
int i;
for (i=0; i<10; i++) {
printf("%3d", Mapping[i]);
}
printf("\n");
}
|