标签:style blog class code tar c
#include <stdio.h> #include <string.h> #include <map> #include <string> using namespace std; char str[10]; map<string, int> idx; void init() { memset(str, 0, sizeof(str)); str[0] = ‘a‘; idx[str] = 1; for (int i = 2; i <= 83681; i++) { for (int j = 4; j >= 0; j--) { if (str[j] != 0) { if (str[j] != ‘z‘) str[j]++; else { int k = j; while (k >= 0) { if (‘z‘ - str[k] == j - k) k--; else break; } if (k != -1) { str[k]++; for (int l = k + 1; l <= j; l++) { str[l] = str[l - 1] + 1; } } else { for (int l = 0; l <= j + 1; l++) str[l] = ‘a‘ + l; } } idx[str] = i; break; } } } } int main() { init(); char s[10]; while (~scanf("%s", s)) { if (idx.count(s)) printf("%d\n", idx[s]); else printf("0\n"); } return 0; }
UVA 417 - Word Index(数论),布布扣,bubuko.com
标签:style blog class code tar c
原文地址:http://blog.csdn.net/accelerator_/article/details/25541989