結果

問題 No.539 インクリメント
ユーザー rankBBNTrankBBNT
提出日時 2017-07-04 23:45:17
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,028 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 54,876 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 16:21:56
合計ジャッジ時間 1,418 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 RE -
testcase_02 AC 4 ms
5,376 KB
testcase_03 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:20: warning: format not a string literal and no format arguments [-Wformat-security]
   21 |             printf(s);
      |                    ^
main.cpp:27:20: warning: format not a string literal and no format arguments [-Wformat-security]
   27 |             printf(s);
      |                    ^
main.cpp:39:24: warning: format not a string literal and no format arguments [-Wformat-security]
   39 |                 printf(s);
      |                        ^
main.cpp:9:10: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     fgets(s, 100002, stdin);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:13:14: warning: ignoring return value of ‘char* fgets(char*, int, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         fgets(s, 100002, stdin);
      |         ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
using namespace std;

int main(void) {
    char s[100000+3];
    fgets(s, 100002, stdin);
    int T = atoi(s);
    
    for (int i=0; i<T; i++) {
        fgets(s, 100002, stdin);
        int len = strlen(s);

        int dpos;
        for (dpos=len-1; dpos>=0; dpos--) {
            if (isdigit(s[dpos])) break;
        }
        if (dpos==-1) {
            printf(s);
            continue;
        }
        
        if (s[dpos]!='9') {
            s[dpos]++;
            printf(s);
            continue;
        }
        
        while (s[dpos]=='9') {
            s[dpos] = '0';
            if (dpos==0 || !isdigit(s[dpos-1])) {
                for (int j = 0; j<dpos; j++) fputc(s[j], stdout);
                fputc('1', stdout);
                for (int j=dpos; j<len; j++) fputc(s[j], stdout);
            } else if (s[dpos-1]!='9') {
                s[dpos-1]++;
                printf(s);
            }
            dpos--;
        }
    }
}
0