-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy path10878.cpp
More file actions
executable file
·71 lines (65 loc) · 1.26 KB
/
10878.cpp
File metadata and controls
executable file
·71 lines (65 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Problem: Decode the tape UVa 10878
Programmer: Md. Mahmud Ahsan
Description: Simulation, Ad hoc
Compiled: Visual C++ 7.0
Date: 21-02-06
*/
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
long convertBase10(char *str, int base){
int len = strlen(str) - 1;
int i, n;
long number = 0;
for (i = 0; str[i]; ++i){
switch(str[i]){
case 'a':
case 'A': n = 10; break;
case 'b':
case 'B': n = 11; break;
case 'c':
case 'C': n = 12; break;
case 'd':
case 'D': n = 13; break;
case 'e':
case 'E': n = 14; break;
case 'f':
case 'F': n = 15; break;
default: n = str[i]-48;
}
number = number + (n * pow((double)base, (double)len));
--len;
}
return number;
}
void removes(char *str){
char n[100], m[100];
int i, j;
j = 0;
for (i = 0; str[i]; ++i){
if (str[i] == ' '){
n[j] = '0';
++j;
}
else if (str[i] == 'o'){
n[j] = '1';
++j;
}
}
n[j] = '\0';
strcpy(str, n);
}
int main(){
//freopen("input.txt", "r", stdin);
char str[100], bin[100];
long dec;
while (cin.getline(str, sizeof(str))){
if (str[0] == '|'){
removes(str);
dec = convertBase10(str, 2);
cout << (char) dec;
}
}
return 0;
}