zoukankan      html  css  js  c++  java
  • POJ2190 HDU2714 ISBN

    USACO 2003 Fall Orange


    问题链接POJ2190 HDU2714 ISBN

    问题简述:参见上述链接。

    问题分析

      单纯的计算问题。需要注意以下几点:

      1.如果是末尾数,则输出为‘X’;

      2.如果能找到对应的值则输出;

      3.如果找不到对应的值则输出-1。

    程序说明

      (略)。

    AC的C++语言程序如下:

    /* POJ2190 HDU2714 ISBN */
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    const int N = 10;
    const int MOD = 11;
    
    int main()
    {
        string s;
        int sum, index, ans;
    
        while(cin >> s) {
            sum = 0;
            index = MOD;
    
            for(int i=0; i<N; i++)
                if(s[i] != '?')
                    if(s[i] != 'X')
                        sum += (N - i) * (s[i] - '0');
                    else
                        sum += N;
                else if(s[i] == '?')
                    index = (N - i);
            
            ans = -1;
            for(int i=0; i<=N; i++)
                if((sum + i * index) % MOD == 0 && i <= N - 1) {
                    cout << i << endl;
                    
                    ans = 0;
                    break;
                } else if((sum + i * index) % MOD == 0 && s[N - 1] == '?') {
                    cout << 'X' << endl;
                    
                    ans = 0;
                    break;
                }
            
            if(ans)
                cout << -1 << endl;
        }
    
        return 0;
    }



  • 相关阅读:
    Choosing the Type at Runtime
    User-Defined Components Must Be Capitalized
    Computed property names
    Controlled Components
    Handling Event
    State
    props
    Functional and Class Components
    招聘漂亮的员工
    Spread Syntax
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7563940.html
Copyright © 2011-2022 走看看