#include #include #include char str[60000]; int str_len = 0; /// /// グローバル変数strの中身を入力された文字列で上書きする /// void readString() { char c = getchar(); str_len = 0; while (c != '\n') { str[str_len] = c; c = getchar(); str_len++; } } void swap(int* nums,int index1,int index2) { int work = nums[index1]; nums[index1] = nums[index2]; nums[index2] = work; } int main() { readString(); int* nums; int max = -1; int index = -1; int start = 0; nums = (int*)malloc(sizeof(int) * str_len); for (int i = 0;i < str_len-1;i++) { for (int j = i+1;j < str_len;j++) { if (nums[i] < nums[j]) break; if (j == str_len - 1) start = i; } } max = -1; for (int i = 0;i < str_len;i++) { nums[i] = str[i] - '0'; } for (int i = start;i < str_len;i++) { if (nums[i] >= max) { index = i; max = nums[i]; } } for (int i = 0;i < index;i++) { if (nums[i] != max) { swap(nums, i, index); break; } } printf("max = %d index = %d start = %d\n", max, index, start); for (int i = 0;i < str_len;i++) { printf("%d",nums[i]); } printf("\n"); }