結果
| 問題 |
No.782 マイナス進数
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2019-01-11 22:13:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 2,000 ms |
| コード長 | 684 bytes |
| コンパイル時間 | 1,564 ms |
| コンパイル使用メモリ | 158,948 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-30 08:11:33 |
| 合計ジャッジ時間 | 3,060 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d%d",&t,&b);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int t,b;
int main(){
scanf("%d%d",&t,&b);
b = -b;
while(t--){
int n;
scanf("%d", &n);
if(n==0){
puts("0"); continue;
}
string s;
while(n){
int c = n%b;
if(c<0)c+=b;
if(s.size()%2==0){
s += string(1,'0'+c);
n -= c;
}else{
c = (b-c)%b;
s += string(1,'0'+c);
n += c;
}
n /= b;
}
reverse(s.begin(), s.end());
puts(s.c_str());
}
return 0;
}
rickytheta