結果

問題 No.39 桁の数字を入れ替え
ユーザー RIGIHRIGIH
提出日時 2017-07-26 02:14:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 804 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 65,544 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 05:46:13
合計ジャッジ時間 1,247 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:21: warning: ‘n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |                 a[n]=x;
      |                 ~~~~^~
main.cpp:7:31: warning: ‘k’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    7 | #define rep(i,n) for(int i=0;i<n;i++)
      |                               ^
main.cpp:26:13: note: ‘k’ was declared here
   26 |         int k;
      |             ^

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define mass 1000000007
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //nの下からk桁目


int main(){
	
	char b[10];
	cin>>b;
	int a[10];
	rep(i,10){
		a[i]=int(b[i])-48;
	}
	aaa:
	int k;
	rep(i,10){
		if(a[i]==-48){
			k=i;
			break;
		}
	}
	int n,m=0;
	rrep(i,k){
		if(a[i]>m){
			m=a[i];
			n=i;
		}
	}
	if(m!=a[0]){
		int x=a[0];
		a[0]=m;
		a[n]=x;
		rep(i,k){
			cout<<a[i];
		}
		cout<<endl;
		return 0;
	}else{
		cout<<a[0];
		rep(i,k){
			a[i]=a[i+1];
		}
		goto aaa;
	}

}
0