yashagl's blog

By yashagl, history, 10 years ago, In English

I have tried many cases its working fine for me but dont know why it gives runtime error on test 6. ;-;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Q_1B_Spreadsheet {
    public static void main(String args[])throws IOException{
        Scanner sc=new Scanner(System.in);
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        long n;
        n=Integer.parseInt(in.readLine());
        long i;
        for(i=0;i<n;i++){
            String s=in.readLine();
            s=s+" ";
            char c=s.charAt(0);
            int j=1;
            long co=0,ro=0;
            if(c=='R' && Character.isDigit(s.charAt(1))==true){
                c=s.charAt(1);
                    while(Character.isDigit(c)==true)
                    {
                        long b=(long) c;
                        b=b-48;
                        co=co*10+b;
                        j++;
                        c=s.charAt(j);
                    }
                    j++;
                    c=s.charAt(j);
                    if(Character.isDigit(c)==true){
                        while(Character.isDigit(c)==true)
                        {
                             long b=(long) c;
                             b=b-48;
                             ro=ro*10+b;
                             j++;
                             c=s.charAt(j);
                        }

                    }
                String na="";
                long a,b=0,d=0;
                a=ro;
                while(a != 0){
                    char c2;
                    if(a%26==0){
                        c2='Z';
                        a=a/26-1;
                    }
                    else{
                        c2=(char)(a%26+64);
                        a=a/26;
                    }
                    na=c2+na;

                }

                 System.out.println(na+co);
            }
            else{
                j=0;
                ro=0;co=0;
                String col="";
                c=s.charAt(0);
                while(Character.isDigit(c)==false)
                {
                    col+=c;
                    j++;
                    c=s.charAt(j);
                }
                while(Character.isDigit(c)==true)
                {
                    long b=(long) c;
                    b=b-48;
                    ro=ro*10+b;
                    j++;
                    c=s.charAt(j);
                }
                for(int k=0;k<col.length();k++){
                    char c1=col.charAt(k);
                    long ab=(long)c1;
                    
                   ab=ab-64;
                  
                    
                    co+=co*26+ab-co;
                }
                
                System.out.println("R"+ro+"C"+co);
               
            }
            
        }
    }
    
}

  • Vote: I like it
  • +8
  • Vote: I do not like it

»
10 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When s[0]='R' and s[1] is a digit there's no need for the test to be the second type.

For example this : R6

  • »
    »
    10 years ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    thanks bro.. I was really depressed with this problem as its my 2nd problem here. Thank You. It solved this problem