The code. The problem is codeforces.com/contest/1/problem/B import java.util.Scanner; public class spreadsheets { public static void main(String[] args) { Scanner sc= new Scanner(System.in); long n = sc.nextLong(); long[] row_arr = new long[99999]; long[] col_arr = new long[99999]; String[] store = new String[9999]; for(int l=0;l<n;l++) { store[l] = sc.next(); } for(int i=0;i<n;i++) { long row =0; long col=0; int c1=0; int c2=1; int c3=0;int c4=0; store[i] = store[i] + '\0'; char c = store[i].charAt(0); char d = store[i].charAt(1); if(c=='R' && (int)d <65) { while(store[i].charAt(c2) !='C') { row_arr[c1] = (Integer.valueOf((store[i].charAt(c2))-48)); c1++; c2++; } c1=c1-1; do { row = row_arr[c3]*(long)Math.pow(10, c1) + row; c1--; c3++; }while(c1>=0); c2++; c1=0; c3=0; while(store[i].charAt(c2) !='\0') { col_arr[c1] = Integer.valueOf(store[i].charAt(c2)-48); c1++; c2++; } c1=c1-1; do { col = col_arr[c3]*(int)Math.pow(10, c1) + col; c1--; c3++; }while(c1>=0); while(true) { if(col%26==0) { if(col<=Math.pow(27, c4)) break; else c4++;
}
else if(col%26!=0)
{
if((col<Math.pow(27, c4)))
break;
else
c4++;
}
}
char[] col_name = new char[c4];
for(int k=(c4-1);k>=0;k--)
{
if(col%26==0)
{
col_name[k] = (char)((col%26) + 90);
col=col-1;
}
else
col_name[k] = (char)((col%26) + 64);
col= (col/26);
}
for(int j=0;j<c4;j++)
{
System.out.print((col_name[j]));
}
System.out.print(row);
System.out.println();
}
else
{
int e=0; int f=0; double sum =0;int temp =0;
int[] rev = new int[99999];
while(store[i].charAt(e)>=65)
{
rev[e] = (store[i].charAt(e))-64;
e++;
}
temp=e;
for(int m=e;m>0;m--)
{
sum = rev[f]*Math.pow(26, (double)(m-1))+sum;
e--;
f++;
}
System.out.print("R");
while(store[i].charAt(temp)!='\0')
{
System.out.print(store[i].charAt(temp)-48);
temp++;
}System.out.println("C"+(int)sum);
}
}
}
}