結果

問題 No.539 インクリメント
ユーザー LayCurseLayCurse
提出日時 2016-01-11 07:08:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 758 bytes
コンパイル時間 1,398 ms
コンパイル使用メモリ 157,164 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 07:21:27
合計ジャッジ時間 2,061 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:7: warning: ‘char* gets(char*)’ is deprecated [-Wdeprecated-declarations]
   13 |   gets(buf);
      |   ~~~~^~~~~
In file included from /usr/include/stdio.h:894,
                 from /usr/include/c++/11/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:46,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:240:1: note: declared here
  240 | gets (char *__str)
      | ^~~~
main.cpp:16:9: warning: ‘char* gets(char*)’ is deprecated [-Wdeprecated-declarations]
   16 |     gets(buf);
      |     ~~~~^~~~~
In file included from /usr/include/stdio.h:894,
                 from /usr/include/c++/11/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:46,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:240:1: note: declared here
  240 | gets (char *__str)
      | ^~~~
main.cpp:13:7: warning: ignoring return value of ‘char* gets(char*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   gets(buf);
      |   ~~~~^~~~~
main.cpp:16:9: warning: ignoring return value of ‘char* gets(char*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     gets(buf);
      |     ~~~~^~~~~
/usr/bin/ld: /tmp/ccp4wkQq.o: in function `main':
main.cpp:(.text.startup+0x22): 警告: the `gets' function is dangerous and should not be used.

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int T, N;
char buf[100010];

int main(){
  int i, j, k;

  gets(buf);
  T = atoi(buf);
  while(T--){
    gets(buf);
    N = strlen(buf);
    for(i=N-1;i>=0;i--) if('0'<=buf[i]&&buf[i]<='9') break;
    if(i==-1){ puts(buf); continue; }
    j = i;
    while(i-1 >= 0 && '0'<=buf[i-1]&&buf[i-1]<='9') i--;

    REP(k,i,j+1) if(buf[k] != '9') break;
    if(k==j+1){
      N++;
      buf[N] = '\0';
      for(k=N-1;k>j+1;k--) buf[k] = buf[k-1];
      buf[i] = '1';
      REP(k,i+1,j+2) buf[k] = '0';
    } else {
      for(k=j;k>=i;k--){
        if(buf[k]!='9'){ buf[k]++; break; }
        buf[k] = '0';
      }
    }
    puts(buf);
  }

  return 0;
}
0