import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
if(line.equals("#")){
break;
}
StringTokenizer st=new StringTokenizer(line);
StringBuilder strBin=new StringBuilder();
while(st.hasMoreTokens()){
String rule=st.nextToken();
if(rule.equals("0")){
strBin.append(st.nextToken());
}else{
int n=st.nextToken().length();
for(int i=0;i<n;i++){
strBin.append(1);
}
}
}
sb.append(Long.parseLong(strBin.toString(), 2)).append('\n');
}
System.out.print(sb);
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
if(line.equals("#")){
break;
}
StringTokenizer st=new StringTokenizer(line);
StringBuilder strBin=new StringBuilder();
while(st.hasMoreTokens()){
String rule=st.nextToken();
if(rule.equals("0")){
strBin.append(st.nextToken());
}else{
int n=st.nextToken().length();
for(int i=0;i<n;i++){
strBin.append(1);
}
}
}
sb.append(Long.parseLong(strBin.toString(), 2)).append('\n');
}
System.out.print(sb);
}
}
No comments:
Post a Comment