POJ 2190

直接枚举0~X就可以了。。。我开始竟然往扩展欧几里德定理想了,呃呃---

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;

char st[20];

int main()
{
    //freopen("t.txt", "r", stdin);
    gets(st);
    int ans = 0;
    int pos = 0;
    for (int i = 0; i < 10; i++)
        if (st[i] == '?')
            pos = 10 - i;
        else if (st[i] == 'X')
            ans += 10 * (10 - i);
        else
            ans += (st[i] - '0') * (10 - i);
    for (int i = 0; i <= 9; i++)
        if ((ans + i * pos) % 11 == 0)
        {
            printf("%d\n", i);
            return 0;
        }
    if ((ans + 10 * pos) % 11 == 0 && pos == 1)
    {
        printf("X\n");
        return 0;
    }
    printf("-1\n");
    return 0;
}

  

posted @ 2015-02-14 23:34  chenjunjie1994  阅读(166)  评论(0编辑  收藏  举报