洛谷P1055 [NOIP2008 普及组] ISBN 号码题解

题目链接

很水的模拟题

要点:判断结果是X的情况字符转数字

不多说,直接上代码

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 1000000000

string str;
int ans;

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> str;
	//字符转数字:字符 - '0'
	ans = ((str[0] - '0') + (str[2] - '0') * 2 + (str[3] - '0') * 3 + (str[4] - '0') * 4 + (str[6] - '0') * 5 + (str[7] - '0') * 6 + (str[8] - '0') * 7 + (str[9] - '0') * 8 + (str[10] - '0') * 9) % 11;
	if (ans == str[12] - '0') cout << "Right";
	else if (ans == 10 && str[12] == 'X') cout << "Right";	//特判最后一位是10的情况
	else
	{
		for (int i = 0 ; i <= 11 ; i++) cout << str[i];
		if (ans != 10) cout << ans;	//特判余数为10的情况
		else cout << "X";
	}
	return 0;
}

提交记录

祝你AC

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值