結果
| 問題 |
No.782 マイナス進数
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2019-01-11 22:11:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 772 bytes |
| コンパイル時間 | 1,212 ms |
| コンパイル使用メモリ | 159,412 KB |
| 実行使用メモリ | 133,108 KB |
| 最終ジャッジ日時 | 2024-11-30 07:34:50 |
| 合計ジャッジ時間 | 18,773 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 RE * 11 TLE * 5 |
コンパイルメッセージ
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;
int bb = 1;
while(n){
int md = bb * b;
int x = n%md;
if(x<0)x += md;
int c = x/bb;
if(s.size()%2==0){
s += string(1,'0'+c);
n -= c*bb;
}else{
c = (b-c)%b;
s += string(1,'0'+c);
n += c*bb;
}
bb = bb*b;
}
reverse(s.begin(), s.end());
puts(s.c_str());
}
return 0;
}
rickytheta