/ 科创班 /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 6ms 256.0 KiB
#2 Accepted 1ms 256.0 KiB
#3 Accepted 18ms 256.0 KiB
#4 Accepted 1ms 204.0 KiB
#5 Accepted 1ms 256.0 KiB
#6 Accepted 4ms 256.0 KiB
#7 Accepted 4ms 256.0 KiB
#8 Accepted 3ms 256.0 KiB
#9 Accepted 5ms 256.0 KiB

代码

#include <stdio.h>

int calc(char* p, int len, int n, char* q)
{
    int i, j = 0, m = 0;
    for (i = 0; i < len; i++)
    {
        m += p[i] * n;
        q[j++] = m % 10;
        m /= 10;
    }
    while (m > 0)
    {
        q[j++] = m % 10;
        m /= 10;
    }
    return j;
}

void print(char* p, int len)
{
    int i = len - 1;
    while (i >= 0) printf("%d", p[i--]);
}

int main()
{
    int i, j = 0, k = 1, n;
    char s1[3000], s2[3000] = {1};
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    {
        if (j > 0)
        {
            k = calc(s1, j, i, s2);
            j = 0;
        }
        else
        {
            j = calc(s2, k, i, s1);
            k = 0;
        }
    }
    if (j > 0)
        print(s1, j);
    else
        print(s2, k);
    return 0;
}

信息

递交者
类型
递交
题目
阶乘计算
题目数据
下载
语言
C
递交时间
2018-10-17 23:47:38
评测时间
2018-10-17 23:47:38
评测机
分数
100
总耗时
47ms
峰值内存
256.0 KiB