結果

問題 No.499 7進数変換
コンテスト
ユーザー p4mf
提出日時 2017-04-07 23:45:26
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 821 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 572 ms
コンパイル使用メモリ 80,552 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-30 18:07:55
合計ジャッジ時間 4,365 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <iostream>
#include <string>
#include <limits>
#include <algorithm>

using namespace std;
#define DEBUG(X) cerr<<__LINE__<<" "<<#X<<": "<<X<<endl;
#define sci(x) int x;scanf("%d",&x);
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);

template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
  static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string ret;
  static numeric_limits<TypeInt> t;
  TypeInt n = v;
  if (t.is_signed) {
    if (v < 0) n *= -1;
  }

  while (n >= base) {
    ret += table[n%base];
    n /= base;
  }
  ret += table[n];
  if (t.is_signed) {
    if (v < 0 && base == 10) ret += '-';
  }
  // 文字列の順番を逆にする
  std::reverse(ret.begin(), ret.end());

  return ret;
}

int main(){
  sci(N)
  cout << Itoa(N, 7) << endl;
}
0