-
Notifications
You must be signed in to change notification settings - Fork 0
/
Broze.cpp
71 lines (49 loc) · 1.14 KB
/
Broze.cpp
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
Task: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output
Output the decoded ternary number. It can have leading zeroes.
Examples
Input
Copy
.-.--
Output
Copy
012
Input
Copy
--.
Output
Copy
20
Input
Copy
-..-.--
Output
Copy
1012
Solution:
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
string s;
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]=='-'&&s[i+1]=='-'){
cout<<2;
i++;
}
else if(s[i]=='-'&&s[i+1]=='.'){
cout<<1;
i++;
}
else{
cout<<0;
}
}
return 0;
}