結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2019-09-13 22:05:01 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 231 ms / 1,000 ms |
| コード長 | 649 bytes |
| コンパイル時間 | 2,053 ms |
| コンパイル使用メモリ | 74,440 KB |
| 実行使用メモリ | 43,464 KB |
| 最終ジャッジ日時 | 2024-07-04 09:43:39 |
| 合計ジャッジ時間 | 5,035 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
String n = sc.next();
sc.close();
StringBuilder sb = new StringBuilder(n);
sb.reverse().append("0");
int ans = 0;
boolean flg = false;
for (int i = 0; i < n.length(); i++) {
if (flg) {
if (sb.charAt(i) == '0') {
ans++;
if (sb.charAt(i + 1) == '0') {
flg = false;
}
}
} else {
if (sb.charAt(i) == '1') {
ans++;
if (sb.charAt(i + 1) == '1') {
flg = true;
}
}
}
}
if (flg) {
ans++;
}
System.out.println(ans);
}
}
ks2m