riku8118's blog

By riku8118, history, 5 years ago, In English

Hi guy. i have a new learner. after i submit problem 1b(spreadsheet), it show runtime error on test6 and the exit code is 11. can you help me to figure the error that i make in my code?

import java.util.Scanner;

public class spreadsheet { public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    char c2;
    int num = input.nextInt();

    String[] str = new String[num];
    boolean[] c1 = new boolean[num];
    input.nextLine();

    for (int i = 0; i < num; i++) {

       str[i] = input.nextLine();
       c1[i] = Character.isDigit(str[i].charAt(1));

    }
    for (int i = 0; i < num; i++) {

       if (str[i].charAt(0) == 'R') {

         if (c1[i]) {
          m1(str[i]);
         } else {
          m2(str[i]);
         }
       }else{
         m2(str[i]);
       }
    }

}

static void m1(String str) {

    int i = 0, start = 0;
    int num1, mod;
    char c1;

    StringBuilder sb1 = new StringBuilder(str);

    str = sb1.substring(1, sb1.length());

    while (str.charAt(i) != 'C') {
       i++;
    }

    String row = str.substring(start, i);
    i = i + 1;
    int num = Integer.parseInt(str.substring(i, str.length()));
    // System.out.println("row: " + row);
    // System.out.println("col: " + col);

    StringBuilder sb = new StringBuilder();

    // num = input.nextInt();

    while (num != 0) {

       num1 = num / 26;
       mod = num % 26;
       // System.out.println("num1: "+num1);
       // System.out.println("mod: " + mod);
       if (mod == 0) {
         c1 = (char) (mod + 90);
         num1 -= 1;
       } else {
         c1 = (char) (mod + 64);
       }
       // System.out.println(c1);
       sb.append(c1);
       num = num1;

    }
    sb.reverse();
    System.out.println(sb + row);

}

static void m2(String str) {

    boolean c1 = false;
    String row = null, col = null;

    for (int i = 0; i < str.length(); i++) {
       c1 = Character.isDigit(str.charAt(i));
       if (c1) {
         row = str.substring(i, str.length());
         col = str.substring(0, (i));

         // System.out.println("row: " + row);
         // System.out.println("col: " + col);

         break;

       }
    }
    int num, sum = 0;
    for (int i = 0; i < col.length(); i++) {
       num = (int) (col.charAt(i)) - 64;
       sum += ((int) Math.pow(26, (col.length() - (i + 1)))) * num;
       // System.out.println("num: "+num);
       // System.out.println("sum: "+sum);
    }

    // System.out.println("sum:" +sum);
    System.out.println("R" + row + "C" + sum);
}

}

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

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I've had the same issue. But I couldn't find a solution.(I use python 3.9 btw)