uva 1584 Circular Sequence(环状串的最小字典序表示法)
2016-07-02 00:20
549 查看
点击打开链接
没什么难点,直接遍历下标比较就行。用变量ans表示当前字典序最小表示方法在该串中的起始位置,
然后移动下标比较字典序,不断更新ans即可。
没什么难点,直接遍历下标比较就行。用变量ans表示当前字典序最小表示方法在该串中的起始位置,
然后移动下标比较字典序,不断更新ans即可。
#include<cstdio> #include<cstdlib> #include<iomanip> #include<string> #include<iostream> #include<cstring> using namespace std; const int maxn = 110; int less_(const char *s, int p, int q)//比较字符串s的p表示方法字典序是否比q表示方法小。 { int len = strlen(s); for(int i = 0; i < len; i++) { if(s[(p+i)%len] != s[(q+i)%len]) return s[(p+i)%len] < s[(q+i)%len]; } return 0;//如果两种表示方法字典序相同,返回0. } int main() { int kase; char s[maxn]; scanf("%d",&kase); while(kase--) { scanf("%s",s); int len = strlen(s), ans = 0; for(int i = 1; i < len; i++) { if(less_(s, i, ans)) ans = i; } for(int i = 0; i < len; i++) { putchar(s[(ans+i) % len]); } putchar('\n'); } return 0; }
相关文章推荐
- SQL Server Extended Events 进阶 3:使用Extended Events UI
- ui-router & ngRoute 学习笔记
- iOS GPUImage之GPUImageFilterGroup组合滤镜(5)
- iOS的UIView和CALayer
- Clojure环境安装与QuickStart
- Extjs整合Ueditor时Dialog被遮挡
- UIScrollView视图
- django-QueryDict 对象
- 常用的自定义控件四(QuickBarView)
- 2015年最全的移动WEB前端UI框架
- iOS GPUImage之GPUImageFilterPipeline组合滤镜(4)
- Import DS JOB issue
- AndroidStudio 报错 finished with non-zero exit value 2
- protues-秒表计时(8255,8253)(内含简单源码-数码管亮)
- Ubuntu 16.04 64位 Sublime build3114 不支持搜狗输入法的解决方案
- 为什么有人说富坚义博有着殿堂级的画功?他的画功体现在哪儿呢?
- Codeforces Round #360 (Div. 2) E. The Values You Can Make
- IEnumerable,IQueryable之前世今生
- 自定义 UISwitch
- LeetCode第60题之Permutation Sequence