UVa 10878 Decode the tape

UVa 10878 Decode the tape
将tape中的'o'变换成1,' '变换成0,'.'不用管,得到的二进制整数就是对应的字符ASCII码。
以下是我的代码:
#include < iostream >
#include
< string >
#include
< cstdio >
using   namespace  std;

int  main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/

    
string  tape;
    getline(cin,tape);
    
while (getline(cin,tape)  &&  tape != " ___________ " )
    {
        
char  ch( 0 );
        
for ( int  i = tape.size() - 2 ,j = 1 ;i >= 2 ;i -- )
        {
            
if (tape[i] == ' . ' )
                
continue ;
            
if (tape[i] == ' o ' )
            {
                ch
+= j;
                j
*= 2 ;
            }
            
else   if (tape[i] == '   ' )
                j
*= 2 ;
        }
        cout
<< ch;
    }

    
return   0 ;
}

你可能感兴趣的:(UVa 10878 Decode the tape)