333

Careful about the problem description,

things to check :

  • there are no more than 10 digits
  • X is at the 10th position
  • to avoid PE avoid the trailing and leading spaces and keep the internal spaces
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>

using namespace std;

int num[15];

int main()
{
	string str,p;
	while(getline(cin,str))
	{
		int k=0;
		p="";
		for(int i=0;i<str.size();i++)
		{
			if((str[i]==' ') && k==0)
			{
			}
			else
			{
				p.append(1u,str[i]);
				k=1;
			}

		}

		for(int i=p.size()-1;i>=0;i--)
		{
			if(p[i]==' ')
			{
				p.erase(i);
			}
			else
			break;
		}
		int idx=0;
		int found=0;
		for(int i=0;i<p.size();i++)
		{
			if(p[i]>='0' && p[i]<='9')
			{
				num[idx++]=p[i]-'0';
			}

			if(idx==9 && p[i]=='X')
			{
				num[idx++]=10;
			}
			else if(idx!=9 && p[i]=='X')
			{
				cout<<p<<" is incorrect.\n";
				found=1;
				break;
			}

			if(idx>10)
			{
				cout<<p<<" is incorrect.\n";
				found=1;
				break;
			}
		}

		if(found==0 && idx<10)
		{
			cout<<p<<" is incorrect.\n";
		}
		else if(found==0 && idx==10)
		{
			for(int i=1;i<10;i++)
			{
				num[i]+=num[i-1];
			}
			for(int i=1;i<10;i++)
			{
				num[i]+=num[i-1];
			}
			if(num[9]%11==0)
			{
				cout<<p<<" is correct.\n";
			}
			else
			cout<<p<<" is incorrect.\n";
		}

	}
	return 0;
}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *