美团前端编程第二题是什么意思,不懂只过了10%

我只理解为把最小的和第一个交换一下位置,过了10%,全ac的大佬解释下这题是什么意思啊
#美团##前端工程师#
全部评论
我判断了第一位是不是最小的,如果是,忽略第一位,继续判断第二位是不是剩下的里面最小的,然后第三位、第四位,迭代的进行下去。。。。也是10%。。不知道为什么。。
点赞 回复 分享
发布于 2017-09-14 22:01
#include<iostream> #include<algorithm> #include<stack> #include<vector> using namespace std; int main(){ int n; cin>>n; vector<string> temp; for(int i=0;i<n;i++){ string str; cin>>str; temp.push_back(str); } vector<string> result = temp; sort(temp.begin(),temp.end()); int j = 0; for(int i=n-1;i>=j;){ if(temp[j]==result[i]&&i==j){ j++; } else if(temp[j]==result[i]&&i!=j){ string str = result[i]; result[i]=result[j]; result[j]=temp[j]; break; } else if(i==n-1){ j++; } } for(int i=0;i<n;i++){ if(i!=n-1){ cout<<result[i]<<" "; } else{ cout<<result[i]; } } return 0; }
点赞 回复 分享
发布于 2017-09-14 22:00
看二进制位,画个状态转移图,典型的有限状态机
点赞 回复 分享
发布于 2017-09-14 22:00
***用py同样%7 可以达到80
点赞 回复 分享
发布于 2017-09-14 21:45

相关推荐

高斯林的信徒:武大简历挂?我勒个骚岗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务