生成打表
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <set>
#include <ctype.h>
#include <string.h>
using namespace std;
const int N = 100005;
const int INF = 1000000;
int main()
{
// freopen("in.txt", "r", stdin);
int a[N], num, T, n;
memset(a, 0, sizeof(a));
for(int i = 1; i < N; i ++)
{
num = i;
int i0 = i;
while(i0 > 0)
{
num += i0 % 10;
i0 /= 10;
}
if(a[num] == 0) a[num] = i;
}
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
printf("%d\n", a[n]);
}
return 0;
}
自己写了以后知道字符串比较是按照字典序啊,以前只是用来比较大小。基础太差了= =。至于环状序列,运用取余数的方法生成比大小就好了,反正也才100的数据量。
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <set>
#include <ctype.h>
#include <string.h>
using namespace std;
const int N = 105;
const int INF = 1000000;
int main()
{
// freopen("in.txt", "r", stdin);
int T;
char st[N], Map[N][N];
scanf("%d", &T);
while(T --)
{
memset(st, 0, sizeof(st));
memset(Map, 0, sizeof(Map));
cin >> st;
int len = strlen(st);
for(int i = 0; i < len; i ++)
for(int j = 0; j < len; j ++)
Map[i][j] = st[(i + j) % len];
strcpy(st, Map[0]);
for(int i = 0; i < len - 1; i ++)
{
if(strcmp(st, Map[i + 1]) > 0) strcpy(st, Map[i + 1]);
}
cout << st << endl;
}
return 0;
}