50蒟蒻求助!!!

P1055 [NOIP2008 普及组] ISBN 号码

YM_1 @ 2024-07-11 11:39:21

代码样例过了,但是只得了50分……

#include <iostream>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <cstdlib>
#include <cctype>
#define ll long long
#define sll static long long
#define db double
#define sti string
#define sint static int
#define lint inline int
#define lb inline bool
#define lll inline long long
using namespace std;
int TurnNum(char);
sti isbn;
int main() {
    cin >> isbn;
    string a = isbn.substr(0, 1);
    string b = isbn.substr(2, 3);
    string c = isbn.substr(6, 5);
    int d = TurnNum(isbn[isbn.length() - 1]);
    string sum = a + b + c;
    int ans = 0;
    for (int i = 0; i < sum.length(); i++) {
        ans += TurnNum(sum[i]) * (i + 1);
    }
    if (ans % 11 == d) {
        cout << "Right";
    }
    else {
        cout << a << '-' << b << '-' << c << '-' << ans % 11;
    }
    return 0;
}
int TurnNum(char ch) {
    return ch - '0';
}

哪位大神大佬愿意帮我一下,Thanks♪(・ω・)ノ


by YM_1 @ 2024-07-11 11:43:17

啊,刚刚忘记判断x了,改了一下,80分

#include <iostream>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <cstdlib>
#include <cctype>
#define ll long long
#define sll static long long
#define db double
#define sti string
#define sint static int
#define lint inline int
#define lb inline bool
#define lll inline long long
using namespace std;
int TurnNum(char);
sti isbn;
int main() {
    cin >> isbn;
    string a = isbn.substr(0, 1);
    string b = isbn.substr(2, 3);
    string c = isbn.substr(6, 5);
    int d = TurnNum(isbn[isbn.length() - 1]);
    string sum = a + b + c;
    int ans = 0;
    for (int i = 0; i < sum.length(); i++) {
        ans += TurnNum(sum[i]) * (i + 1);
    }
    if (ans % 11 == d) {
        cout << "Right";
    }
    else {
        if (ans % 11 == 10)
            cout << a << '-' << b << '-' << c << '-' << 'X';
        else
            cout << a << '-' << b << '-' << c << '-' << ans % 11;
    }
    return 0;
}
int TurnNum(char ch) {
    return ch - '0';
}

by Ahws_rwhy @ 2024-07-12 00:18:32

@Zhourenyu0214 这个识别码可以是X。


by Ahws_rwhy @ 2024-07-12 00:19:03

@Zhourenyu0214 加个特判


by YM_1 @ 2024-07-12 10:31:06

已经AC了,谢谢Thanks♪(・ω・)ノ @rwhy


|