nyoj 1057寻找最大数(三) 贪心
来源:互联网 发布:h265网络直播编码器 编辑:程序博客网 时间:2024/05/22 11:49
#include <stdio.h>#include <string.h>int main(){char temp,str[20];int k,len,mark,flag,j;while(scanf("%s %d",str,&k)!=EOF){len=strlen(str);if(k==0){puts(str);continue;}for(int i=0;i<len;i++){temp=str[i],flag=1;for(j=i+1;j<=i+k&&j<len;j++){//贪心,从i+1到i+k寻找最大的数 并记录下序号if(str[j]>temp)temp=str[j],mark=j,flag=0;}if(!flag){for(int q=mark;q>i;q--)//一步一步相邻的交换。。第一次以为直接两个数交换位置,结果错了。。temp=str[q],str[q]=str[q-1],str[q-1]=temp;k=k-mark+i;}if(k==0)break;}puts(str);}return 0;}
2 0
- NYOJ 1057 寻找最大数(三)(贪心)
- nyoj 1057 寻找最大数(三) 贪心
- NYOJ 1057 寻找最大数(三) (贪心)
- nyoj 1057寻找最大数(三) 贪心
- nyoj--1057--寻找最大数(三)(贪心)
- NYOJ 1057 寻找最大数(三)贪心算法
- NYOJ 1057 寻找最大数(三)(贪心)
- NYOJ 1057 寻找最大数(三)(贪心)
- nyoj 1057 寻找最大数(三)
- nyoj 1057 寻找最大数(三)
- NYOJ 1057 寻找最大数(三)
- NYOJ 1057 寻找最大数(三)
- NYOJ 1057 寻找最大数(三)
- nyoj 1057 寻找最大数(三)
- nyoj 1057-寻找最大数(三)
- NYOJ 1057 寻找最大数(三)
- nyoj 1057寻找最大数(三)
- NYOJ 1057 寻找最大数(三)
- publickey,gssapi-with-mic,Unspecified GSS failure
- ZigZag Conversion
- 自定义布局 标题栏
- 先学习搭建个架子:Eclipse java EE版 + S2SH + Oracle11g + Plsql.(2)
- ubuntu中 Vim 配置文件 + tip +自由复制粘贴
- nyoj 1057寻找最大数(三) 贪心
- MySQL 当记录不存在时插入,当记录存在时更新
- Quick Sort
- 2015年武汉腾讯校园招聘一面经历—后台开发
- jquery.cookie.js
- 2. 正则表达式
- Window Server2012 配置PHP+mysql环境
- 图片渲染的实现方式
- cocos2dx 事件监听