标签:style io ar color os sp for on 数据
给出一个整数N,每次可以移动2个相邻数位上的数字,最多移动K次,得到一个新的整数。
求这个新的整数的最大值是多少。
1990 1 100 0 9090000078001234 6
9190 100 9907000008001234
#include<iostream> #include<stdio.h> #include<string.h> using namespace std; char a[1000]; int main() { int k,i,j,max; while(cin>>a>>k) { int t=strlen(a); max=0; int m=k,b=0; while(k>0) { for(i=b+1;i<t&&m>0;i++) { if(a[i]>a[max]) max=i; m--; } for(i=max-1;i>=b;i--) { swap(a[i],a[i+1]); k--; } m=k; b++; max=b; if(b==t)//防止死循环没有跳出while(k>0)这个循环 { break; } } cout<<a<<endl; } return 0; }
标签:style io ar color os sp for on 数据
原文地址:http://blog.csdn.net/phytn/article/details/41777675