OpenJudge

3414代码交流

  • bugczw
    bugczw 13天前 回复

    求看3414代码,不知道哪里错了,QAQ,以下为代码:
    #include<stdio.h>

    int move(int* arr, int n, int m)
    {
    int num = 0;
    long long k = 1;
    if (arr[n - 1] == 1)
    {
    for (int i = 0; i < n; i++)
    {
    num += k * arr[n - 1 - i];
    num = num % m;
    k = k * 2;
    }
    }
    else
    {
    k = k * 2;
    for (int i = 0; i < n; i++)
    {
    num += k * arr[n - 1 - i];
    num = num % m;
    k = k * 2;
    }
    num = (num - 1) % m;
    }
    return num;
    }


    int main()
    {
    while (1)
    {
    int n, m;
    char c=getchar();
    if (c == EOF)
    break;
    scanf("%d", &n);
    scanf("%d", &m);
    int* arr = new int[m];
    for (int i = 0; i < n; i++)
    scanf("%d", &arr[i]);
    printf("%d\n", move(arr, n, m));
    }
    return 0;
    }

想要评论吗?

注册OpenJudge账号,如果您已经注册,请先登入