結果
| 問題 |
No.2246 1333-like Number
|
| コンテスト | |
| ユーザー |
lotoka
|
| 提出日時 | 2023-04-16 21:48:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 797 bytes |
| コンパイル時間 | 553 ms |
| コンパイル使用メモリ | 68,896 KB |
| 最終ジャッジ日時 | 2025-02-12 09:19:26 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:29: warning: ‘a’ may be used uninitialized [-Wmaybe-uninitialized]
23 | string ans = to_string(a);
| ^
main.cpp:5:9: note: ‘a’ was declared here
5 | int a, b, c;
| ^
In file included from /usr/include/c++/13/string:54,
from /usr/include/c++/13/bits/locale_classes.h:40,
from /usr/include/c++/13/bits/ios_base.h:41,
from /usr/include/c++/13/ios:44,
from /usr/include/c++/13/ostream:40,
from /usr/include/c++/13/iostream:41,
from main.cpp:1:
In function ‘std::string std::__cxx11::to_string(int)’,
inlined from ‘int main()’ at main.cpp:25:25:
/usr/include/c++/13/bits/basic_string.h:4168:35: warning: ‘b’ may be used uninitialized [-Wmaybe-uninitialized]
4168 | const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:5:12: note: ‘b’ was declared here
5 | int a, b, c;
| ^
ソースコード
#include <iostream>
using namespace std;
int main() {
int a, b, c;
int N;
cin >> N;
c = (N - 1) / 36 + 1; //cは単純な計算で算出
int temp = (N - 1) % 36 + 1; //abの値を出すため
int sum = 0; //今後の判別用
for (int i = 1; i < 9; ++i) { //大量のif文を繋げる事もできるがスマートでないためfor文を用いる. a, bの値を定める.
if (sum + 1 <= temp && temp <= sum + 9 - i) {
a = i;
b = i + temp - sum;
break; //a,bの値が定まればこのfor文に用はなくなるので脱出
}
sum += 9 - i;
}
string ans = to_string(a);
for (int i = 0; i < c; ++i) {
ans += to_string(b);
}
cout << ans << endl;
return 0;
}
lotoka