nyoj 143 第几是谁?

来源:互联网 发布:js tab页面切换 编辑:程序博客网 时间:2024/04/28 23:30

题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=143

参考:http://blog.csdn.net/hearthougan/article/details/24741179

#include <iostream>#include <cstdio>#include <cstring>#include <climits>using namespace std;int fac[12];void Inite_Fac(){    int i;    fac[0] = fac[1] = 1;    for(i = 2; i < 12; ++i)        fac[i] = i * fac[i-1];}int main(){    char str[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'};    int T, num, tmp, i, j, temp;    char ans[12], str1[12];    Inite_Fac();    scanf("%d", &T);    while(T--)    {        scanf("%d", &num);        memset(str1, 0, sizeof(str1));        strcpy(str1, str);        temp = num-1;        for(i = 0; i < 12; ++i)        {            tmp = temp/fac[11-i];            printf("%c", str1[tmp]);            for(j = tmp; j < 12-i; ++j)                str1[j] = str1[j+1];            temp -= tmp * fac[11-i];        }        printf("\n");    }    return 0;}


0 0
原创粉丝点击