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