結果

問題 No.39 桁の数字を入れ替え
コンテスト
ユーザー FF256grhy
提出日時 2016-09-04 01:10:17
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 838 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 195 ms
コンパイル使用メモリ 40,848 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-18 17:04:40
合計ジャッジ時間 1,368 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>

#define FOR(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define REV(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define INC0(i, n) FOR(i, 0, n)
#define INC1(i, n) FOR(i, 1, (n) + 1)
#define DEC0(i, n) REV(i, 0, n)
#define DEC1(i, n) REV(i, 1, (n) + 1)

typedef long long   signed int LL;
typedef long long unsigned int LU;


int n, d[9];

int swap(int x, int y, int len) {
	int a[9];
	INC0(i, len) { a[i] = d[i]; }
	
	int temp = a[x];
	a[x] = a[y];
	a[y] = temp;
	
	int ans = 0, p = 1;
	INC0(i, len) { ans += a[i] * p; p *= 10; }
	
	return ans;
}

int main() {
	scanf("%d", &n);
	
	int i = 0, t = n, len;
	while(t != 0) {
		d[i] = t % 10;
		t /= 10;
		i++;
	}
	len = i;
	
	int max = n;
	
	INC0(i, len) {
	INC0(j, i) {
		int s = swap(i, j, len);
		if(max < s) { max = s; }
	}
	}
	
	printf("%d\n", max);
	
	return 0;
}
0