java解决方法:
- import java.util.*;
- import java.io.*;
- public class Main{
- public static void main(String[] args) throws IOException {
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- String line;
- while ((line = in.readLine()) != null) {
- int len = line.length();
- int sum = 0;
- int j = 0;
- for(int i = 2; i < len; i++)
- {
- char c = line.charAt(i);
- if(c >= '0' && c <= '9')
- {
- sum = sum * 16 + (c - '0');
- }
- else if(c >= 'A' && c <= 'F')
- {
- sum = sum * 16 + (c - 'A' + 10);
- }
- }
- String str = String.valueOf(sum);
- System.out.println(str);
- }
- }
- }
java解决方法:
- import java.io.*;
- public class Main{
- public static void main(String[] args) throws IOException{
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- String line;
- line = in.readLine();
- while(!line.equals("0"))
- {
- int num = 0;
- int len = line.length();
- for(int i = 0; i < len; i++)
- {
- num = num * 10 + line.charAt(i) - '0';
- }
- int num1 = num;
- int count = 0;
- int yushu = 0;
- while(num1 >= 2)
- {
- if(num1 == 2)
- {
- num1 = (num1 + 1) / 3;
- yushu = 0;
- count++;
- }
- else
- {
- yushu = num1 % 3;
- num1 = num1 / 3;
- count = count + num1;
- num1 = num1 + yushu;
- }
- }
- System.out.println(String.valueOf(count));
- line = in.readLine();
- }
- }
- }