結果

問題 No.1458 Segment Function
ユーザー tentententen
提出日時 2022-07-28 10:35:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,754 bytes
コンパイル時間 4,304 ms
コンパイル使用メモリ 77,464 KB
実行使用メモリ 41,316 KB
最終ジャッジ日時 2024-04-20 17:43:36
合計ジャッジ時間 6,702 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,016 KB
testcase_01 AC 55 ms
36,872 KB
testcase_02 AC 54 ms
36,900 KB
testcase_03 AC 56 ms
36,860 KB
testcase_04 AC 54 ms
36,648 KB
testcase_05 AC 53 ms
36,904 KB
testcase_06 AC 55 ms
36,624 KB
testcase_07 AC 55 ms
37,016 KB
testcase_08 AC 116 ms
39,844 KB
testcase_09 AC 114 ms
39,696 KB
testcase_10 AC 114 ms
39,716 KB
testcase_11 AC 111 ms
39,844 KB
testcase_12 AC 101 ms
39,976 KB
testcase_13 AC 106 ms
39,896 KB
testcase_14 AC 105 ms
39,800 KB
testcase_15 AC 104 ms
39,560 KB
testcase_16 AC 107 ms
39,588 KB
testcase_17 AC 105 ms
39,836 KB
testcase_18 AC 127 ms
41,316 KB
testcase_19 AC 133 ms
41,196 KB
testcase_20 AC 127 ms
41,240 KB
testcase_21 AC 130 ms
41,268 KB
testcase_22 AC 129 ms
41,304 KB
testcase_23 AC 55 ms
36,504 KB
testcase_24 AC 112 ms
39,916 KB
testcase_25 AC 54 ms
36,560 KB
testcase_26 AC 127 ms
41,256 KB
testcase_27 AC 132 ms
40,992 KB
testcase_28 AC 54 ms
36,896 KB
testcase_29 AC 115 ms
39,980 KB
testcase_30 AC 111 ms
39,652 KB
testcase_31 AC 103 ms
40,016 KB
testcase_32 AC 101 ms
39,836 KB
testcase_33 AC 114 ms
39,720 KB
testcase_34 AC 105 ms
39,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int[] WEIGHTS = new int[]{6, 2, 5, 5, 4, 5, 6, 4, 7, 6};
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] p = sc.next().toCharArray();
        char[] num = sc.next().toCharArray();
        int count;
        if (num.length < 3) {
            count = Math.min(7, Integer.parseInt(new String(num)));
        } else {
            count = 7;
        }
        if (count == 0) {
            System.out.println(p);
            return;
        }
        int ans = 0;
        for (char c : p) {
            if (c == '-') {
                ans++;
            } else {
                ans += WEIGHTS[c - '0'];
            }
        }
        for (int i = 0; i < count - 1; i++) {
            ans = getAns(ans);
        }
        System.out.println(ans);
    }
    
    static int getAns(int x) {
        int ans = 0;
        while (x > 0) {
            ans += WEIGHTS[x % 10];
            x /= 10;
        }
        return ans;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0