首页 > 代码库 > UVa 11743 - Credit Check

UVa 11743 - Credit Check

题目:判断卡号是否合法,给你4组4位的数字,偶数位的2倍的位和加上奇数位的和,判断尾数是否为0。

分析:简单题,模拟。直接按照提议判断即可。

说明:460题,加油!

#include <iostream>
#include <cstdlib>

using namespace std;

char data[4][5];

int main()
{
	int n;
	while (cin >> n) 
	for (int i = 1 ; i <= n ; ++ i) {
		for (int i = 0 ; i < 4 ; ++ i)
			cin >> data[i];
		
		int d = 0,u = 0,t = 0;
		for (int i = 0 ; i < 4 ; ++ i) {
			t = (data[i][0]-'0')*2;
			d += (t/10+t%10);
			u += (data[i][1]-'0');
			t = (data[i][2]-'0')*2;
			d += (t/10+t%10);
			u += (data[i][3]-'0');
		}
		
		if ((d+u)%10)
			cout << "Invalid" << endl;
		else cout << "Valid" << endl;
	}
	return 0;
}
 

UVa 11743 - Credit Check