[NOIP2006] Jam的计数法
★ 输入文件:counting.in
输出文件:counting.out
简单对比
时间限制:1 s 内存限制:64 MB
[题目]
输入:
输出:
[样例输入]
2 10 5 bdfij
[样例输出]
bdghi bdghj bdgij bdhij befgh
面对这种题首先要审清题意.
搞清楚题意后直接模拟就行了.
(1)初始串从后往前找.找到第一个"符合"的位置(想想怎么符合).
(2)从这个位置开始修改.
#include<cstdio> #include<cstring> using namespace std; int s, t, w; char str[30]; bool nextp() { int loc; for (int i = strlen(str) - 1;; --i) { if (i < 0) return true; if (str[i] < t - w + i + 'a') { loc = i; break; } } str[loc] += 1; for (int i = loc + 1; i < strlen(str); ++i) str[i] = str[i - 1] + 1; return false; } int main() { freopen("counting.in", "r", stdin); freopen("counting.out", "w", stdout); scanf("%d%d%d", &s, &t, &w); scanf("%s", str); for (int i = 0; i < 5; ++i) { if (nextp()) break; printf("%s\n", str); } return 0; }