您的位置:首页 > 产品设计 > UI/UE

UVa1584——Circular Sequence

2015-09-20 15:18 302 查看
题目很简单。直接暴力过。求解字典序最小的字符串。

下面的是AC的代码:

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
int t, i, j, k;
char str[110];
char temp[110], ans[110];
while(cin >> t)
{
while(t--)
{
cin >> str;
int length = strlen(str);
strcpy(ans, str);
for(i = 1; i < length; i++)
{
k = 0;
for(j = i; j < length; j++)
temp[k++] = str[j];
for(j = 0; j < i; j++)
temp[k++] = str[j];
temp[k] = '\0';
if(strcmp(temp, ans) < 0)
strcpy(ans, temp);
}
cout << ans << endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: