2014-09-05

10878 - Decode the tape




題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1819

解法概念:假設每行oooo.ooo由左到右分別是2^6,2^5,2^4.....2^0,有圈的位數做相加,相加的值即為ASCII碼,之後轉成字元輸出


import java.util.*;
import java.lang.*;
import java.lang.Math;

public class Main{

 public static void main(String[] args) {

  Scanner console = new Scanner(System.in);
  
  char[] decodedChar =new char[100000];
  
  int index=0;
  int count =0;
     int size=0;
     boolean can=true;
  while(count!=2){
   size++;
   String encodedLine = console.nextLine();
   can =true;  
   int exp=7,ascii=0;
   
   for(int i=0 ; i<encodedLine.length();i++){
    
    if(encodedLine.charAt(i)=='_'){
     can=false;
     count++;
     break;
    }
    else if(encodedLine.charAt(i)=='|'||encodedLine.charAt(i)=='.')
        continue;
    
    else if(encodedLine.charAt(i)=='o')
     ascii+=Math.pow(2, exp);
     
     exp--; 
   }
  if(can){
   decodedChar[index]=(char)ascii;
   index++;
  }
  }
  String temp = new String(decodedChar);
  String output = temp.substring(0,size-2);
  System.out.print(output);
  
   
  }
        
  
 }


沒有留言:

張貼留言

(VM) Ubuntu enable ssh

OS版本:14.04 LTS 相關指令: sudo apt-get install openssh-server Port forwarding設定 : 以virtual box為例子,網路->進階->連接阜轉送(port forwarding) ...