import java.util.*;
import java.util.Scanner;
public class HexiacosadecimalNumber{
//attributes
//public
// public String stringRepresentation;
// public double doubleRepresentation;
/** constructors*/
public HexiacosadecimalNumber(){}
/*public HexiacosadecimalNumber(double doubleRepresentation){
this.doubleRepresentation = doubleRepresentation;
}
public HexiacosadecimalNumber(String stringRepresentation){
this.stringRepresentation = stringRepresentation;
}*/
public void paopao(String stringtemp)
{
//ringRepresentation;
double temp = 0;
double dottemp = 0;
int dotindex = 0;
int fuFlag = 0;
int i = 0;
int dotflag = 0;
if(stringtemp.charAt(i) == '-')
{
i++;
fuFlag = 1;
}
else
fuFlag = 0;
//while((stringtemp.charAt(i) != '.') && (stringtemp.length()-i-1 != 0))
for(;i<stringtemp.length();i++)
{
if(stringtemp.charAt(i) == '.')
{
dotindex = i;
dotflag = 1;
continue;
}
if(dotflag == 0)
// System.out.println(stringtemp.charAt(i));
temp = (temp*26)+((double)(stringtemp.charAt(i) -'a'));
else
{
double tempdouble1 = (double)(stringtemp.charAt(i) -'a');
for(int j=0;j<i-dotindex;j++)
{
tempdouble1 /= 26;
}
//System.out.println(tempdouble1);
//dottemp = (dottemp/ 26)+((double)(stringtemp.charAt(i) -'a'));
dottemp += tempdouble1 ;
}
}
temp = temp + dottemp;
if(fuFlag == 0)
System.out.println(stringtemp+"("+temp+")");
else
System.out.println(stringtemp+"(-"+temp+")");
}
public String change(double dub)
{
String str;
str = String.valueOf(dub);
return str;
}
public void momo(double doubleRepresentation)
{
int fuFlag = 0;
int dotflag = 0;
String allNum = change(doubleRepresentation);
//System.out.println(allNum);
String intNum="";
String dotNum="";
for(int i=0;i<allNum.length();i++)
{
if(allNum.charAt(i) != '.')
continue;
else
{
dotflag = 1;
break;
}
}
if(dotflag == 1)
{
intNum = allNum.substring(0,allNum.indexOf('.'));
dotNum = allNum.substring(allNum.indexOf('.')+1);
}
else
{
intNum = allNum.substring(0);
dotNum = "";
}
String coutint="";
int doubleintNum = 0;
for(int i=0;i<intNum.length();i++)
{
doubleintNum = doubleintNum * 10 + ((int)(intNum.charAt(i) - '0'));
}
//System.out.println(doubleintNum);
while(doubleintNum != 0)
{
String tempstr = "";
tempstr += (char)((doubleintNum % 26) + 'a');
doubleintNum /=26;
tempstr += coutint;
coutint = tempstr.setUserInput(0);
}
System.out.println(coutint);
//System.out.println(intNum + " --- " + dotNum);
// toString 需要重写
//String strtemp = toString(doubleRepresentation);
/* if(strtemp.charAt(i) == '-')
{
fuFlag = 1;
i++;
}
else
{
fuFlag = 0;
}
for(;i<strtemp.length();i++)
{
if(strtemp.charAt(i) == '.')
{
dotindex = 1;
dotflag = 1;
continue;
}
if(dotflag == 0)
{
//整数部分
}
else
{
}
}*/
}
public void setUserInput(){
while(true){
Scanner input = new Scanner(System.in);
char charflag;
while(true)
{
String ch;
//char ch=(char)System.in.read();
System.out.println("Please enter 'h' to convert from Hexiacosadecimal to decimal, or 'd' to convert from decimal to Hexiacosadecimal.");
//scan.hasNext();
ch = input.next();
charflag = ch.charAt(0);
//charflag= ch;
if((charflag!='h')&&(charflag!='H')&&(charflag!='d')&&(charflag!='D')&&(charflag != 'q') && (charflag != 'Q'))
{
System.out.println("INVALID INPUT");
}
else
{
break;
}
}
if (charflag == 'h'|| charflag == 'H'){
String strtemp;
//canner input1 = new Scanner(System.in);
System.out.println("Please enter your hexiacosadecimal number: ");
// input.next();
strtemp = input.next();
//this.stringRepresentation = stringRepresentation;
// System.out.println(strtemp);
paopao(strtemp);
}
else if(charflag == 'd' || charflag == 'D')
{
double doubleRepresentation;
//Scanner input2 = new Scanner(System.in);
System.out.println("Please enter your decimal number: ");
doubleRepresentation = input.nextDouble();
momo(doubleRepresentation);
}
else
{
break;
}
}
}
public static void main(String[] args)
{
HexiacosadecimalNumber myHexiacosadecimalNumber = new HexiacosadecimalNumber();
myHexiacosadecimalNumber.setUserInput();
}
}