Codeforces Round #249 (Div. 2) —— B
2014-08-13 14:59
357 查看
B. Pasha Maximizes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Pasha has a positive integer a without
leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Sample test(s)
input
1990 1
output
9190
input
300 0
output
300
input
1034 2
output
3104
input
9090000078001234 6
output
9907000008001234
题意:用k次只交换相邻的数字使得新的数字尽量大。
这题似乎不难,但我做了很久,还看过别人的代码 ==。
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Pasha has a positive integer a without
leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.
Help Pasha count the maximum number he can get if he has the time to make at most k swaps.
Input
The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).
Output
Print the maximum number that Pasha can get if he makes at most k swaps.
Sample test(s)
input
1990 1
output
9190
input
300 0
output
300
input
1034 2
output
3104
input
9090000078001234 6
output
9907000008001234
题意:用k次只交换相邻的数字使得新的数字尽量大。
这题似乎不难,但我做了很久,还看过别人的代码 ==。
#include<bits/stdc++.h> using namespace std; int main() { int k, i, j; char a[20]; while(~scanf("%s%d", a,&k)) { int len = strlen(a); for(i=0; i<len; i++) { int index = i; for(j=i+1; j<len && j<=i+k; j++) { if(a[j] > a[index]) index = j; } if(index != i) for(j=index; j>i; j--) swap(a[j],a[j-1]), k--; } printf("%s\n", a); } return 0; }
相关文章推荐
- Codeforces Round #249 (Div. 2) A. Queue on Bus Stop
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
- Codeforces Round #249 (Div. 2)C Devu and Partitioning of the Array
- Codeforces Round #249 (Div. 2) C. Cardiogram
- Codeforces Round #249 (Div. 2)C Devu and Partitioning of the Array
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
- Codeforces Round #249 (Div. 2) A B
- Codeforces Round #249 (Div. 2) A题
- Codeforces Round #172 (Div. 2)
- Educational Codeforces Round 33 (Rated for Div. 2) C
- Codeforces Round #173 (Div. 2)
- Educational Codeforces Round 33 (Rated for Div. 2) A - Chess For Three
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons
- Codeforces Round #205 (Div. 2) : B
- Codeforces 584 A. Olesya and Rodion(Codeforces Round #324 (Div. 2))
- Codeforces Round #174 (Div. 1) (A, B, C)
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree(dfs+最大公约数+因子+树)
- Codeforces Round #305 (Div. 2)--A. Mike and Fax
- Codeforces Round #354 (Div. 2) B (模拟)