ISBN码字符串c++

这题充满了玄学问题!!!用cin.getline竟然会报错;而且输出一些不得了的东西。看来有时候还是要用cin了啊!!!

#include<bits/stdc++.h>
using namespace std;
int n,m,x,s,y;
int main()
{
	char  a[500],b[500];
	cin>>a;
	for(int i=0;i<strlen(a)-1;i++)
	{
		if(a[i]>='0'&&a[i]<='9')
		{
		    y++;
		    s++;
		     b[y]=a[i];  
		    
		}
	}
	for(int k=1;k<=s;k++)
	n+=(b[k]-48)*k;
	if(a[strlen(a)-1]=='X') x=10;
	else x=a[strlen(a)-1]-48;	
	m=n%11;
	if(m==x)
	{
	    cout<<"Right";
		return 0;
	}
	else
	{
		for(int j=0;j<strlen(a)-1;j++) cout<<a[j];  
	    if (m!=10) cout<<m; 
		else cout<<"X";
    }
	return 0;
}

  

转载于:https://www.cnblogs.com/5t2y0/p/9239435.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值