zoukankan      html  css  js  c++  java
  • pku 2498 StuPId

    主要是看题,要把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;
    }

  • 相关阅读:
    1582. Special Positions in a Binary Matrix
    623. Add One Row to Tree
    617. Merge Two Binary Trees
    643. Maximum Average Subarray I
    645. Set Mismatch
    1022. Sum of Root To Leaf Binary Numbers
    835. Image Overlap
    HDU Marriage is Stable (稳定婚姻匹配)
    HDU Stable Match (稳定婚姻匹配)
    HDU Maximum Clique (最大团)
  • 原文地址:https://www.cnblogs.com/FreeAquar/p/1952885.html
Copyright © 2011-2022 走看看