結果
問題 |
No.1458 Segment Function
|
ユーザー |
![]() |
提出日時 | 2022-07-28 10:35:40 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 1,754 bytes |
コンパイル時間 | 2,222 ms |
コンパイル使用メモリ | 78,224 KB |
実行使用メモリ | 41,768 KB |
最終ジャッジ日時 | 2024-10-12 13:39:32 |
合計ジャッジ時間 | 6,737 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
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(); } }