Pages

Friday, 12 October 2012

UVA - 10878 - Decode the tape


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        StringBuffer sb = new StringBuffer("");
        br.readLine();
        String m="";
       
        while (true) {
           
            if("___________".equals(m))
                break;
            sb.append(charS(m));
           
            }
        System.out.print(sb);
    }
    static char charS(String x){
        int sum=0;
           for(int i=x.length()-2,ind=1;i>0;i--,ind*=2){
               if(x.charAt(i)=='.')
                   i--;
               if(x.charAt(i)=='o')
                   sum+=ind;
           }
           return (char) sum;
    }
}

No comments:

Post a Comment