B. Borze
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputTernary 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.
Sample test(s)
Input
.-.--
Output
012
Input
--.
Output
20
Input
-..-.--
Output
1012#include<cstring> #include<iostream> using namespace std; int main(){ int i,k,len; char s[200],num[200]; while(cin>>s){ memset(num,0,sizeof(num)); k=0; len=strlen(s); for(i=0;i<len;i++){ if(s[i]=='-'){ if(s[i+1]=='-'){ num[k]='2'; } else if(s[i+1]=='.'){ num[k]='1'; } k++; i++; } else if(s[i]=='.'){ num[k]='0'; k++; } } cout<<num<<endl; } return 0; }
本文介绍了一个简单的程序,该程序能够将一种特殊的Borze编码(使用「..」、「-.」、「--」分别表示0、1、2)转换为对应的三进制数值。通过解析输入字符串并逐字符检查,程序能够正确地识别并转换这些特殊符号,最终输出原始的三进制数。
1333

被折叠的 条评论
为什么被折叠?



