結果
| 問題 | No.39 桁の数字を入れ替え | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-06-15 14:59:58 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 576 bytes | 
| コンパイル時間 | 1,238 ms | 
| コンパイル使用メモリ | 158,396 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-30 14:49:07 | 
| 合計ジャッジ時間 | 1,861 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |     scanf("%s", s);
      |     ~~~~~^~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
char s[100];
int n, k, m;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    scanf("%s", s);
    n = strlen(s);
    
    
    for (int i = 0; i < n; i++) {
        m = 0;
        for (int j = i +1; s[j]; j++) {
            if ((s[j]-'0') >= m)
                m = s[k=j]-'0';
        }
        
        if (s[i]-'0' < m) {
            char t = s[k];
            s[k] = s[i];
            s[i] = t;
            
            break;
        }
    }
    printf("%s\n", s);
    return 0;
}
            
            
            
        