主要是看题,要把id number 反过来乘以9,3,7的循环

然后……poj不支持strrev()函数……不信的可以自己试试……

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int cas[10]={9,3,7,9,3,7,9};

void strreved( char *source )
{
    int l = strlen( source );
    char temp;
    int i;
    for( i = 0; i < l / 2; i++ )
    {
    temp = source[i];
    source[i] = source[l-i-1];
    source[l-i-1] = temp;
    }
}
int main()
{
    int n, sum, flag, j;
    char num[10];
    while(scanf("%d", &n)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            sum=0;
            scanf("%s", num);
            printf("Scenario #%d:\n", i);
            strreved(num);
            int len = strlen(num);
            for(j=0; j<len; j++)
            {
                if(num[j]>='0' && num[j]<='9')
                {
                    sum+=cas[j]*(num[j]-'0');
                }
                else
                    flag=j;
            }
            for(j=0; j<10; j++)
                if((j*cas[flag]+sum)%10==0)
                    break;
            num[flag]=j+'0';
            strreved(num);
            cout<<num<<endl<<endl;
        }
    }
    return 0;
}

posted on 2011-02-12 22:58  FreeAquar  阅读(226)  评论(0编辑  收藏  举报