50分,急,样例通

P1055 [NOIP2008 普及组] ISBN 号码

baibaobao666 @ 2023-02-27 18:34:32

抓办?

#include <iostream>
#include <string>
using namespace std;

int in(string n)
{
    if(n == "1")
    return 1;
    else if(n == "2")
    return 2;
    else if(n == "3")
    return 3;
    else if(n == "4")
    return 4;
    else if(n == "5")
    return 5;
    else if(n == "6")
    return 6;
    else if(n == "7")
    return 7;
    else if(n == "8")
    return 8;
    else if(n == "9")
    return 9;
    else if(n == "0")
    return 0;
}

int main()
{
    string n;
    cin >> n;
    string x,ac=n.substr(0,12);
    int sum = 0,last = 0,ans=0;
    x = n.substr(0,1)+n.substr(2,3)+n.substr(6,5);
    for(int i = 1;i <= 9;i++)
    {
        sum += in(x.substr(i-1,1)) * i;//0-670-82162-4
        //cout << sum << endl;
        //cout << in(x.substr(i,1)) * i << endl;
    }
    ans = sum % 11;
    if(ans == in(n.substr(12,1)))
    {
        cout << "Right";
    }
    else
    {
        cout << ac << ans;
    }

    return 0;
}

by baibaobao666 @ 2023-02-27 18:44:29

又80了qwq

#include <iostream>
#include <string>
using namespace std;

int in(string n)
{
    if(n == "1")
    return 1;
    else if(n == "2")
    return 2;
    else if(n == "3")
    return 3;
    else if(n == "4")
    return 4;
    else if(n == "5")
    return 5;
    else if(n == "6")
    return 6;
    else if(n == "7")
    return 7;
    else if(n == "8")
    return 8;
    else if(n == "9")
    return 9;
    else if(n == "0")
    return 0;
}

int main()
{
    string n;
    cin >> n;
    string x,ac=n.substr(0,12);
    int sum = 0,last = 0,ans=0;
    x = n.substr(0,1)+n.substr(2,3)+n.substr(6,5);
    for(int i = 1;i <= 9;i++)
    {
        sum += in(x.substr(i-1,1)) * i;//0-670-82162-4
        //cout << sum << endl;
        //cout << in(x.substr(i,1)) * i << endl;
    }
    ans = sum % 11;
    if(ans == in(n.substr(12,1)))
    {
        cout << "Right";
    }
    else
    {
        if(ans != 10)
        cout << ac << ans;
        else
        cout << ac << "X";
    }

    return 0;
}

|