新旧身份证(继承)

aa

#include <iostream>
#include <string>
using namespace std;

int YY1[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int YY2[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int id1[17] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
char checkCode[11] = { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' };

class CDate {
private:
	int year;
	int month;
	int day;
public:
	CDate() {};
	CDate(int, int, int);
	void datain() {
		cin >> year >> month >> day;
	}
	int getyear() {
		return year;
	}
	int getmonth() {
		return month;
	}
	int getday() {
		return day;
	}
	bool check() {
		if (year > 2017 || year == 2017 && month > 5 || year == 2017 && month == 5 && day > 10)
			return false;
		if (isLeap())
		{
			if (YY1[month - 1] < day)
				return false;
		}
		else {
			if (YY2[month - 1] < day)
				return false;
		}
		return true;
	}
	string tostring() {
		string a = to_string(year);
		string b = to_string(month);
		string c = to_string(day);
		if (b.length() == 1)
			b.insert(b.begin(), '0');
		if (c.length() == 1)
			c.insert(c.begin(), '0');
		a.append(b);
		a.append(c);
		return a;
	}
	bool isLeap() {
		if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
			return true;
		else 
			return false;
	}
	void print() {
		cout << year << "年" << month << "月" << day << "日 ";
	}
};
class COldID {
protected:
	string pid15;
	string p_name; //15位身份证号码,姓名
	CDate birthday; //出生日期
public:
	COldID() {}
	void datain() {
		cin >> p_name;
		birthday.datain();
		cin >> pid15;
	}
	bool check() {
		cout << p_name << endl;
		if (!birthday.check())
			return false;
		if (pid15.length() != 15)
			return false;
		for (int i = 0; i < 15; i++) {
			if (!isdigit(pid15[i]))
				return false;
		}
		return true;
	} 
	void print() {}
	~COldID() {}
};
class CNewID : public COldID
{
private:
	string pid18;
	CDate issueday;
	int vyear;
public:
	CNewID() {
		COldID::datain();
		cin >> pid18;
		issueday.datain();
		cin >> vyear;
	}
	bool check() {
		if (!COldID::check())
			return false;
		if (pid18.substr(0, 5) != pid15.substr(0, 5) || pid18.substr(8, 8) != pid15.substr(6, 8))
			return false;
		if (pid18.find(birthday.tostring()) == -1) 
			return false;
		if (!issueday.check())
			return false;
		if (pid18.length() != 18)
			return false;
		int temp = 0;
		for (int i = 0; i < 17; i++) {
			temp += (pid18[i] - '0') * id1[i];
		}
		temp %= 11;
		if (checkCode[temp] != pid18[17])
			return false;
		if (issueday.getyear() + vyear < 2017 || issueday.getyear() + vyear == 2017 && issueday.getmonth() > 5 || issueday.getyear() + vyear == 2017 && issueday.getmonth() == 5 && issueday.getday() > 10)
			return false;
		return true;
	}
	void print() {
		COldID::print();
		cout << pid18 << " ";
		issueday.print();
		if (vyear < 100)
			cout << vyear << "年" << endl;
		else cout << "长期" << endl;
	}
};

int main() {
	int t;
	cin >> t;
	while (t--) {
		CNewID nsfz;
		if (nsfz.check())
		{
			nsfz.print();
		}	
		else
		{
			cout << "illegal id" << endl;
		}
			
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值