Created
February 21, 2017 01:40
-
-
Save behitek/693de46c844623e22952d3b09f210dc4 to your computer and use it in GitHub Desktop.
Quả Cân – LASCALE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.vtcc.antispam.hieunv.quacan; | |
import java.util.Scanner; | |
import java.util.Vector; | |
/** | |
* Created by HieuNguyen on 02/20/2017. | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int arr[] = new int[100]; | |
arr[0] = 1; | |
for(int i = 1;i < 30;i++) arr[i] = arr[i-1]*3; | |
int a; | |
while(true){ | |
Vector<Integer> left = new Vector<Integer>(); | |
Vector<Integer> right = new Vector<Integer>(); | |
a = sc.nextInt(); | |
left.add(a); | |
Vector<Integer> s = new Vector<>(); | |
while(a > 0){ | |
s.add(a%3); | |
a = a/3; | |
} | |
for(int i = 0;i < s.size();i++){ | |
if(s.elementAt(i) == 1){ | |
right.add(arr[i]); | |
}else if(s.elementAt(i) == 2){ | |
left.add(arr[i]); | |
if(i+1 == s.size()) s.add(1); | |
else s.set(i+1,s.elementAt(i+1)+1); | |
}else if(s.elementAt(i) == 3){ | |
if(i+1 == s.size()) s.add(1); | |
else s.set(i+1,s.elementAt(i+1)+1); | |
} | |
} | |
System.out.println(left); | |
System.out.println(right); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment