UVA
来源:互联网 发布:xss攻击 java 编辑:程序博客网 时间:2024/06/05 10:17
//环状序列 uva1584//收获://如何判断环状序列的字典序:取余的巧妙应用,但是注意仅比较长度次数,否则循环可能无法退出,故要 n = strlen(s) i从0到(n-1), 比较n次即可 #include <iostream>#include <cstring>using namespace std;int maxn = 105;//环状串s的表示法p是否比表示法q的字典序小 int CompareSequence(const char*s, int p, int q){int n = strlen(s);for (int i = 0; i < n; i++)if (s[(i + p) % n] != s[(i + q) % n])return ( s[(i + p) % n] < s[(i + q) % n] );return 0;}int main(){int t;cin >> t;char s[105];while (t--){cin >> s;int ans = 0, n = strlen(s);for (int i = 0; i < n; i++)if (CompareSequence(s, i, ans)) ans = i;for (int i = 0; i < n; i++)cout << s[(i + ans) % n];cout << endl;}return 0;}
阅读全文
0 0
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- 盒子居总结(display:block)
- 吾日三省
- 微信小程序图片链接加入正常,控制台报404错误解决方案
- 机器学习基础--贝叶斯分类器
- 剑指Offer—64—滑动窗口的最大值
- UVA
- [ERROR] WSREP: gcs/src/gcs_group.cpp:gcs_group_handle_join_msg():765: Will never receive state. Need
- Keras中的神经网络层组件简介
- Ansible安装和使用
- 基于SSM 的 Office 在线编辑
- c++树状数组2模板
- 剑指Offer—65—矩阵中的路径
- ssm框架下实现文件上传
- 将博客搬至CSDN