1-三维空间的点
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
class C2D
{
protected:
double x;
double y;
public:
C2D() {};
C2D(double x1, double y1) :x(x1), y(y1) {};
void getDistance() {
cout<< setprecision(6) <<sqrt(x * x + y * y)<<endl;
}
};
class C3D :public C2D
{
protected:
double z;
public:
C3D(){};
C3D(double x1, double y1,double z1) :C2D(x1,y1),z(z1){};
void getDistance() {
cout<<setprecision(6) << sqrt(x * x + y * y + z * z) << endl;
}
};
int main() {
double x1, y1;
double x, y, z;
cin >> x1 >> y1;
C2D C(x1,y1);
C.getDistance();
cin >> x >> y >> z;
C3D C1(x, y, z);
C1.getDistance();
cin >> x >> y >> z;
C3D C2(x, y, z);
C2.getDistance();
C2D C3(x, y);
C3.getDistance();
}
2-学生成绩计算
using namespace std;
#include<iostream>
#include<string.h>
class person {
protected:
int age;
string name;
public:
person() {}
person(int age, string name) {
this->age = age;
this->name = name;
}
void display() {
cout << name << " " << age << endl;
}
};
class R :public person {
int usual;
int exam;
char general;
public:
R() {}
R( string name, int age,int usual, int exam) {
this->age = age;
this->name = name;
this->usual = usual;
this->exam = exam;
}
void setgeneral(char c) {
general=c;
}
void display() {
cout << name << " " << age << " " << general << endl;
}
};
class S :public person {
int exam;
char general;
public:
S() {}
S( string name,int age, int exam) {
this->age = age;
this->name = name;
this->exam = exam;
}
void setgeneral(char c) {
general = c;
}
void display() {
cout << name << " " << age << " " << general << endl;
}
};
int main() {
int t;
cin >> t;
while (t--) {
char c;
float num;
int usual;
int exam;
int age;
string name;
cin >> c;
if (c == 'R') {
cin >> name >> age >> usual >> exam;
R R0(name, age, usual, exam);
num = usual * 0.4 + exam * 0.6;
if (num < 60) R0.setgeneral('F');
else if (num >= 60 && num <65 ) R0.setgeneral('D');
else if (num >= 65 && num < 75) R0.setgeneral('C');
else if (num >= 75 && num < 85) R0.setgeneral('B');
else if (num >= 85) R0.setgeneral('A');
R0.display();
} else if (c == 'S') {
cin >> name >> age >> exam;
S S0(name, age, exam);
num = exam;
if (num < 60) S0.setgeneral('F');
else if (num >= 60 && num < 65) S0.setgeneral('D');
else if (num >= 65 && num < 75) S0.setgeneral('C');
else if (num >= 75 && num < 85) S0.setgeneral('B');
else if (num >= 85) S0.setgeneral('A');
S0.display();
}
}
}
3-存折与信用卡
using namespace std;
#include<iostream>
#include<string.h>
class CAccount
{
protected:
long account;
string name;
float balance;
public:
CAccount(){}
CAccount(long account, string name, float balance) {
this->account = account;
this->name = name;
this->balance = balance;
}
void deposit(int a) {
cout << "saving ok!" << endl;
balance += a;
cout << "balance is " << balance<<endl;
}
void withdraw(int a) {
if (a > balance) {
cout << "sorry! over balance!" << endl;
cout << "balance is " << balance << endl;
}
else {
cout << "withdraw ok!" << endl;
balance -= a;
cout << "balance is " << balance << endl;
}
}
void check() {
cout << "balance is " << balance << endl;
}
};
class CCreditcard :public CAccount
{
float limit;
public:
CCreditcard(){}
CCreditcard(long account, string name, float balance, float limit) {
this->account = account;
this->name = name;
this->balance = balance;
this->limit = limit;
}
void withdraw(int a) {
if (a > balance + limit) {
cout << "sorry! over limit!" << endl;
cout << "balance is " << balance << endl;
}
else {
cout << "withdraw ok!" << endl;
cout << "balance is " << balance - a << endl;
}
}
};
int main() {
long account;
string name;
float balance;
float limit;
int deposit;
int withdraw;
cin >> account >> name >> balance>>deposit>>withdraw;
CAccount CA(account, name, balance);
CA.check();
CA.deposit(deposit);
CA.withdraw(withdraw);
cin >> account >> name >> balance >>limit>> deposit >> withdraw;
CCreditcard CC(account, name, balance,limit);
CC.check();
CC.deposit(deposit);
CC.withdraw(withdraw);
}
4-圆和圆柱体计算
using namespace std;
#include<iostream>
#include<iomanip>
class CPoint
{
protected:
int x;
int y;
public:
CPoint(){}
CPoint(int x, int y) {
this->x = x;
this->y = y;
}
};
class CCircle :public CPoint
{
protected :
int r;
public:
CCircle(){}
CCircle(int x, int y,int r){
this->x = x;
this->y = y;
this->r = r;
}
float getArea() {
return 3.14*(r*r);
}
};
class CCylinder :CCircle
{
int h;
public:
CCylinder(){}
CCylinder(int x, int y, int r,int h) {
this->x = x;
this->y = y;
this->r = r;
this->h = h;
}
float getV() {
return h * getArea();
}
};
int main() {
int x, y,r,h;
cin >> x >> y >> r;
CCircle CC(x, y, r);
cout << "Circle:(" << x << "," << y << ")," << r << endl;
cout << "Area:" <<fixed<<setprecision(2) << CC.getArea() << endl;
cin >> x >> y >> r >> h;
CCylinder CCC(x, y, r, h);
cout<<"Cylinder:("<< x << "," << y << ")," << r <<"," <<h<< endl;
cout << "Volume:" <<fixed<<setprecision(2) << CCC.getV() << endl;
}
5-时钟模拟
#include<iostream>
using namespace std;
#include<cstring>
class CDate
{
protected:
int year, month, day;
public:
int getYear() { return year; }
int getMonth() { return month; }
int getDay() { return day; }
CDate(){}
CDate(int a, int b, int c):year(a),month(b),day(c){};
CDate(CDate& D) { year = D.year; month = D.month; day = D.day; }
bool check(); //检验日期是否合法
bool isLeap();
void print();
};
bool CDate::check() {
if (year > 0 && month > 0 && month <= 12 && day > 0 && day <=31)
return true;
else
return false;
}
bool CDate::isLeap() {
return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0);
}
void CDate::print() {
cout << year << "年" << month << "月" << day << "日";
}
class COldID
{
protected:
char* p_id15, * p_name; //15位身份证号码,姓名
CDate birthday; //出生日期
public:
COldID() {};
COldID(char* p_idval, char* p_nameval, CDate& day) :birthday(day) {
p_id15 = new char[strlen(p_idval) + 1];
strcpy(p_id15, p_idval);
p_name = new char[strlen(p_nameval) + 1];
strcpy(p_name, p_nameval);
}
COldID(COldID &ID):birthday(ID.birthday.getYear(), ID.birthday.getMonth(),ID.birthday.getDay()) {
p_id15 = new char[strlen(ID.p_id15) + 1];
strcpy(p_id15, ID.p_id15);
p_name = new char[strlen(ID.p_name) + 1];
strcpy(p_name, ID.p_name);
}
bool check(); //验证15位身份证是否合法
void print(){ cout << p_name << endl; };
~COldID(){};
};
bool COldID::check() {
if (strlen(p_id15) != 15|| !birthday.check())
return 0;
for (int i = 0; i < 15; i++) {
if ('0' > *(p_id15 + i) || *(p_id15 + i) > '9')
return 0;
if ((*(p_id15 + 6) - '0') * 10 + (*(p_id15 + 7) - '0') != birthday.getYear() % 100 ||
(*(p_id15 + 8) - '0') * 10 + (*(p_id15 + 9) - '0') != birthday.getMonth() ||
(*(p_id15 + 10) - '0') * 10 + (*(p_id15 + 11) - '0') != birthday.getDay())
return 0;
return 1;
}
}
class CNewID :public COldID
{
char* p_id18;//(18位号码);
CDate issueday;//(签发日期);
int validyear;//(有效期,年数)
public:
CNewID(){}
CNewID(char* name, int y1, int m1, int d1, char* p15, char* p18, int y2, int m2, int d2, int v)
:issueday(y2, m2, d2), validyear(v) {
CDate CD(y1, m1, d1);
COldID(p15, name, CD);
p_id18 = new char[strlen(p18) + 1];
strcpy(p_id18, p18);
}
bool check(){}
void print(){}
};
bool CNewID::check() {
if (strlen(p_id18) != 18) return 0;
for (int i = 0; i < strlen(p_id18); i++)
if (*(p_id18 + i) != 'X' && (*(p_id18 + i) > '9' || *(p_id18 + i) < '0')) return 0;
static char u[20]; //字符串的传递,需要用到static
for (int i = 0; i < 6; i++) {
u[i] = *(p_id15 + i);
}
if (birthday.getYear() < 2000) {
u[6] = '1';
u[7] = '9';
}
else {
u[6] = '2';
u[7] = '0';
}
for (int i = 8; i < 17; i++) {
u[i] = *(p_id15 + i - 2);
}
int add[] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
char drr[12] = { '1','0','X','9','8','7','6','5','4','3','2','\0' };
int sum = 0;
for (int i = 0; i < 17; i++) {
sum += ((u[i] - '0') * add[i]);
}
sum %= 11;
u[17] = drr[sum];
u[18] = '\0';
if (strcmp(u, p_id18) != 0 || !issueday.check()
||!( ((issueday.getYear() + validyear) > 2015 ||
((issueday.getYear() + validyear) == 2015 && issueday.getMonth() < 4) ||
((issueday.getYear() + validyear) == 2015 && issueday.getMonth() == 4 && issueday.getDay() < 7))))
return 0;
return 1;
}
void CNewID::print() {
cout << p_id18 << " ";
issueday.print();
if (validyear != 100)
cout << " " << validyear << "年" << endl;
else
cout << " 长期" << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
char name[5];
char oldC[16];
char newC[19];
int day, month, year;
int day1, month1, year1;
int valid;
cin >> name >> year >> month >> day >> oldC >> newC >> year1 >> month1 >> day1 >> valid;
CNewID c(name, year, month, day, oldC, newC, year1, month1, day1,valid);
c.COldID::print();
if (c.COldID::check() && c.check())
c.print();
else
cout << "illegal id" << endl;
}
}
6-新旧身份证
//不想写!!!!!!!!!!!!!!!!!!!!!
//老师的代码
#include<iostream>
#include<cmath>
using namespace std;
class C2D
{
protected:
double x, y;
public:
C2D(double x1, double y1): x(x1), y(y1) {}
double getDistance()
{ return sqrt(x*x+y*y);}
};
class C3D: public C2D{
private:
double z;
public:
C3D(double x1, double y1, double z1): C2D(x1, y1), z(z1) {}
double getDistance()
{ return sqrt(x*x+y*y+z*z);}
};
int main()
{
double x, y, z;
cin>>x>>y;
C2D p1(x, y);
cout<<p1.getDistance()<<endl;
cin>>x>>y>>z;
C3D p2(x, y, z);
cout<<p2.getDistance()<<endl;
cin>>x>>y>>z;
C3D p3(x, y, z);
cout<<p3.getDistance()<<endl;
p1=p3;
cout<<p1.getDistance()<<endl;
return 0;
}
=================================================
#include<iostream>
using namespace std;
class Person{
string name;
int age;
public:
Person(){}
Person(string name,int age):name(name),age(age){}
void display(){cout<<name<<" "<<age<<" ";}
char grade(int score){
char grade;
if(score>=85)
grade='A';
else if(score>=75)
grade='B';
else if(score>=65)
grade='C';
else if(score>=60)
grade='D';
else
grade='F';
return grade;
}
};
class Student1:public Person{
int score1,score2;
public:
Student1(){}
Student1(string name,int age,int score1,int score2):Person(name,age),score1(score1),score2(score2){}
void display(){
Person::display();
int score;
score=(int)(score1*0.4+score2*0.6+0.5); //成绩四舍五入,所以加0.5
cout<<grade(score)<<endl;
}
};
class Student2:public Person{
int score1;
public:
Student2(){}
Student2(string name,int age,int score1):Person(name,age),score1(score1){}
void display(){
Person::display();
int score;
score=(int)(score1+0.5); //成绩四舍五入,所以加0.5
cout<<grade(score)<<endl;
}
};
int main(){
int t,age,score1,score2;
char type;
string name;
cin>>t;
while(t--){
cin>>type;
if(type=='R'){
cin>>name>>age>>score1>>score2;
Student1 stu(name,age,score1,score2);
stu.display();
}
else{
cin>>name>>age>>score1;
Student2 stu(name,age,score1);
stu.display();
}
}
return 0;
}
=================================================
///1、姓名用string表示
#include<iostream>
using namespace std;
class CAccount
{
protected:
long account;
string name;
float balance;
public:
CAccount(long a,string n,float b):account(a),name(n),balance(b){}
void check() //查询
{
cout<<"balance is "<<balance<<endl;
}
void deposit(float num) //存款
{
balance += num;
cout<<"saving ok!"<<endl;
}
void withdraw(float num) //取款
{
if( balance >= num )
{
balance -= num;
cout<<"withdraw ok!"<<endl;
}
else
cout<<"sorry! over balance!"<<endl;
}
};
class CCreditcard:public CAccount
{
protected:
float limit;
public:
CCreditcard(long a,string n,float b,float l):CAccount(a,n,b),limit(l){}
void withdraw(float num)
{
if( limit+balance >= num )
{
cout<<"withdraw ok!"<<endl;
balance-=num;
}
else
cout<<"sorry! over limit!"<<endl;
}
};
int main()
{
long id1;
string name;
float balance,depo,with,limit;
cin>>id1>>name>>balance>>depo>>with;
CAccount ca(id1,name,balance);
ca.check();
ca.deposit(depo);
ca.check();
ca.withdraw(with);
ca.check();
cin>>id1>>name>>balance>>limit>>depo>>with;
CCreditcard cc(id1,name,balance,limit);
cc.check();
cc.deposit(depo);
cc.check();
cc.withdraw(with);
cc.check();
return 0;
}
//
2、姓名用char name[10]表示
#include<iostream>
#include<cstring>
using namespace std;
class CAccount
{
protected:
long account;
char name[10];
float balance;
public:
CAccount(){}
CAccount(long a,char n[],float b):account(a),balance(b)
{
strcpy(name,n);
}
void check()
{
cout<<"balance is "<<balance<<endl;
}
void deposit(float num)
{
balance += num;
cout<<"saving ok!"<<endl;
}
void withdraw(float num)
{
if( balance >= num )
{
balance -= num;
cout<<"withdraw ok!"<<endl;
}
else
cout<<"sorry! over balance!"<<endl;
}
};
class CCreditcard:public CAccount
{
protected:
float limit;
public:
CCreditcard(){}
CCreditcard(long a,char n[],float b,float l):CAccount(a,n,b),limit(l){}
void withdraw(float num)
{
if( limit+balance >= num )
{
cout<<"withdraw ok!"<<endl;
balance-=num;
}
else
cout<<"sorry! over limit!"<<endl;
}
};
int main()
{
long id1;
char name[10];
float balance,depo,with,limit;
cin>>id1>>name>>balance>>depo>>with;
CAccount ca(id1,name,balance);
ca.check();
ca.deposit(depo);
ca.check();
ca.withdraw(with);
ca.check();
cin>>id1>>name>>balance>>limit>>depo>>with;
CCreditcard cc(id1,name,balance,limit);
cc.check();
cc.deposit(depo);
cc.check();
cc.withdraw(with);
cc.check();
return 0;
}
=================================================
#include<iostream>
using namespace std;
class CPoint{
protected:
double x,y;
public:
CPoint(double x1,double y1):x(x1),y(y1){}
};
class CCircle:public CPoint{
protected:
double r;
public:
CCircle(double x1,double y1,double r1):CPoint(x1,y1),r(r1){}
double getArea(){
return 3.14*r*r;
}
void print(){
cout<<"Circle:("<<x<<","<<y<<"),"<<r<<endl;
cout<<"Area:"<<getArea()<<endl;
}
};
class CCylinder:public CCircle{
private:
double h;
public:
CCylinder(double x1,double y1,double r1,double h1):CCircle(x1,y1,r1),h(h1){}
double getVol(){
return getArea()*h;
}
void print(){
cout<<"Cylinder:("<<x<<","<<y<<"),"<<r<<","<<h<<endl;
cout<<"Volume:"<<getVol()<<endl;
}
};
int main()
{
double x,y,r,h;
cin>>x>>y>>r;
CCircle c(x,y,r);
c.print();
cin>>x>>y>>r>>h;
CCylinder cylinder(x,y,r,h);
cylinder.print();
return 0;
}
=================================================
#include<iostream>
using namespace std;
class CCounter{
protected:
int value;
public:
CCounter(int v):value(v){}
bool increment(){
value++;
return true;
}
int getVal(){
return value;
}
};
class CLoop:public CCounter{
private:
int max,min;
public:
CLoop(int v,int ma,int mi):CCounter(v),max(ma),min(mi){}
bool increment()
{ value++;
if(value>max){
value=min;
return true;
}
else
return false;
}
};
class CClock{
CLoop hour,minute,second;
public:
CClock(int h,int m,int s):hour(h,23,0),minute(m,59,0),second(s,59,0){}
void time(int s){
while(s--){
if(second.increment()){
if(minute.increment()){
hour.increment();
}
}
}
}
void print(){
cout<<hour.getVal()<<":"<<minute.getVal()<<":"<<second.getVal()<<endl;
}
};
int main()
{
int t,hour,minute,second,s;
cin>>t;
while(t--)
{
cin>>hour>>minute>>second>>s;
CClock c(hour,minute,second);
c.time(s);
c.print();
}
return 0;
}
=================================================
#include<cstring>
#include<iostream>
using namespace std;
class CDate {
private:
int year,month,day;
public:
CDate(int y=0,int m=0,int d=0):year(y),month(m),day(d){}
bool check(){
int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; //第一个月的天数用mon[1]表示
if(isLeap())
mon[2]++;
if(year<=0||month<1||month>12||day<1||day>mon[month]) //验证日期的合法性
return false;
return true;
}
bool isLeap(){
return (year%4==0&&year%100!=0)||(year%400==0);
}
void print(){cout<<year<<"年"<<month<<"月"<<day<<"日 ";}
int getYear(){return year;}
int getMonth(){return month;}
int getDay(){return day;}
void setYear(int y){ year=y;}
};
class COldID {
protected:
char *p_id15,*p_name;
CDate birthday;
public:
COldID(char *p_idval,char *p_nameval,int y,int m,int d) : birthday(y,m,d){
p_id15=new char[strlen(p_idval)+1];
p_name=new char[strlen(p_nameval)+1];
strcpy(p_id15,p_idval);
strcpy(p_name,p_nameval);
}
bool check(){
int lenth=strlen(p_id15);
if(lenth!=15) //验证长度是否为15位
return false;
for(int i=0;i<lenth;i++){ //验证是否都是数字
if(!isdigit(p_id15[i]))
return false;
}
if(birthday.check()==false) //验证出生年月合法性
return false;
int a1,b1,a2,b2,a3,b3,y,m,d; //验证身份证上的年月日和出生年月日是否相同
a1=p_id15[6]-'0';
b1=p_id15[7]-'0';
y=1900+a1*10+b1; //老身份证默认19几几年
a2=p_id15[8]-'0';
b2=p_id15[9]-'0';
m=a2*10+b2;
a3=p_id15[10]-'0';
b3=p_id15[11]-'0';
d=a3*10+b3;
if(y!=birthday.getYear()||m!=birthday.getMonth()||d!=birthday.getDay())
return false;
return true;
}
void print(){
if(check()==false)
{cout<<"illegal id"<<endl;}
else
{cout<<p_name<<endl;cout<<p_id15<<" "<<endl;}
}
~COldID(){delete[]p_name;delete[]p_id15;}
};
class CNewID:public COldID {
private:
char *p_id18;
CDate issueday;
int validyear;
public:
CNewID(char *p_nameval,int y1,int m1,int d1,char *p_idval1,char *p_idval,int y2,int m2,int d2,int validyear): COldID (p_idval1,p_nameval,y1,m1,d1), issueday(y2,m2,d2),validyear(validyear){
p_id18=new char[strlen(p_idval)+1];
strcpy(p_id18,p_idval);
}
char find(){ //求检验码
int sum=0;
int a[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char b[11]={'1','0','X','9','8','7','6','5','4','3','2'};
for(int i=0;i<17;i++){
sum+=(p_id18[i]-'0')*a[i];
}
sum%=11;
return b[sum];
}
bool check(){
int lenth=strlen(p_id18);
if(!COldID::check()) //先验证15位身份证的正确性
return false;
if(lenth!=18) //验证18位身份证长度
return false;
for(int i=0;i<lenth-1;i++){ //验证18位身份证的前17位是否为数字
if(!isdigit(p_id18[i]))
return false;
}
if(p_id18[17]!=find()) //验证第18位校验码
return false;
if(issueday.check()==false) //验证发证日期的正确性
return false;
for(int i=0;i<6;i++) //验证18位身份证是否和15位身份证一致
if(p_id18[i]!=p_id15[i])
return false;
for(int i=6, j=8;i<15;i++,j++)
if(p_id18[j]!=p_id15[i])
return false;
int a1,b1,c1,d1,a2,b2,a3,b3,y,m,d; //验证18位身份证上的年月日是否和出生年月日一致
a1=p_id18[6]-'0';
b1=p_id18[7]-'0';
c1=p_id18[8]-'0';
d1=p_id18[9]-'0';
y=a1*1000+b1*100+c1*10+d1; //年
a2=p_id18[10]-'0';
b2=p_id18[11]-'0';
m=a2*10+b2; //月
a3=p_id18[12]-'0';
b3=p_id18[13]-'0';
d=a3*10+b3; //日
if(y!=birthday.getYear()||m!=birthday.getMonth()||d!=birthday.getDay())
return false;
y=issueday.getYear()+validyear; //验证身份证是否在有效期内
m=issueday.getMonth();
d=issueday.getDay();
if(y<2017||(y==2017&&m<5)||(y==2017&&m==5&&d<10))
return false;
return true;
}
void print(){
cout<<p_name<<endl;
if(check()==false)
{cout<<"illegal id"<<endl;}
else
{cout<<p_id18<<" ";
issueday.print();
if(validyear>=100)
cout<<"长期"<<endl;
else
cout<<validyear<<"年"<<endl;
}
}
~CNewID(){delete[]p_id18;}
};
int main() {
int t;
char p_id15[128],p_id18[128], p_name[128];
int validyear;
int y1,y2,m1,m2,d1,d2;
cin>>t;
while(t--){
cin>>p_name>>y1>>m1>>d1>>p_id15>>p_id18>>y2>>m2>>d2>>validyear;
CNewID a(p_name,y1,m1,d1,p_id15,p_id18,y2,m2,d2,validyear);
a.print();
}
return 0;
}
//
用string
#include<cstring>
#include<iostream>
using namespace std;
class CDate {
private:
int year,month,day;
public:
CDate(int y=0,int m=0,int d=0):year(y),month(m),day(d){}
bool check(){
int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(isLeap())
mon[2]++;
if(year<=0||month<1||month>12||day<1||day>mon[month])
return false;
return true;
}
bool isLeap(){
return (year%4==0&&year%100!=0)||(year%400==0);
}
void print(){cout<<year<<"年"<<month<<"月"<<day<<"日 ";}
int getYear(){return year;}
int getMonth(){return month;}
int getDay(){return day;}
void setYear(int y){ year=y;}
};
class COldID {
protected:
string p_id15,p_name;
CDate birthday;
public:
COldID(string p_idval,string p_nameval,int y,int m,int d) : p_id15(p_idval),p_name(p_nameval),birthday(y,m,d){}
bool check(){
int lenth=p_id15.length();
if(lenth!=15)
return false;
for(int i=0;i<lenth;i++){
if(!isdigit(p_id15[i]))
return false;
}
if(birthday.check()==false)
return false;
int a1,b1,a2,b2,a3,b3,y,m,d;
a1=p_id15[6]-'0';
b1=p_id15[7]-'0';
y=1900+a1*10+b1;
a2=p_id15[8]-'0';
b2=p_id15[9]-'0';
m=a2*10+b2;
a3=p_id15[10]-'0';
b3=p_id15[11]-'0';
d=a3*10+b3;
if(y!=birthday.getYear()||m!=birthday.getMonth()||d!=birthday.getDay())
return false;
return true;
}
void print(){
if(check()==false)
{cout<<"illegal id"<<endl;}
else
{cout<<p_name<<endl;cout<<p_id15<<" "<<endl;}
}
};
class CNewID:public COldID {
private:
string p_id18;
CDate issueday;
int validyear;
public:
CNewID(string p_nameval,int y1,int m1,int d1,string p_idval1,string p_idval,int y2,int m2,int d2,int validyear): COldID (p_idval1,p_nameval,y1,m1,d1), issueday(y2,m2,d2), validyear(validyear),p_id18(p_idval){}
char find(){
int sum=0;
int a[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char b[11]={'1','0','X','9','8','7','6','5','4','3','2'};
for(int i=0;i<17;i++){
sum+=(p_id18[i]-'0')*a[i];
}
sum%=11;
return b[sum];
}
bool check(){
int lenth=p_id18.length();
if(!COldID::check())
return false;
if(lenth!=18)
return false;
for(int i=0;i<lenth-1;i++){
if(!isdigit(p_id18[i]))
return false;
}
if(p_id18[17]!=find())
return false;
if(issueday.check()==false)
return false;
for(int i=0;i<6;i++)
if(p_id18[i]!=p_id15[i])
return false;
for(int i=6, j=8;i<15;i++,j++)
if(p_id18[j]!=p_id15[i])
return false;
int a1,b1,c1,d1,a2,b2,a3,b3,y,m,d;
a1=p_id18[6]-'0';
b1=p_id18[7]-'0';
c1=p_id18[8]-'0';
d1=p_id18[9]-'0';
y=a1*1000+b1*100+c1*10+d1;
a2=p_id18[10]-'0';
b2=p_id18[11]-'0';
m=a2*10+b2;
a3=p_id18[12]-'0';
b3=p_id18[13]-'0';
d=a3*10+b3;
if(y!=birthday.getYear()||m!=birthday.getMonth()||d!=birthday.getDay())
return false;
y=issueday.getYear()+validyear;
m=issueday.getMonth();
d=issueday.getDay();
if(y<2017||(y==2017&&m<5)||(y==2017&&m==5&&d<10))
return false;
return true;
}
void print(){
cout<<p_name<<endl;
if(check()==false)
{cout<<"illegal id"<<endl;}
else
{cout<<p_id18<<" ";
issueday.print();
if(validyear>=100)
cout<<"长期"<<endl;
else
cout<<validyear<<"年"<<endl;
}
}
};
int main() {
int t;
string p_id15,p_id18, p_name;
int validyear;
int y1,y2,m1,m2,d1,d2;
cin>>t;
while(t--){
cin>>p_name>>y1>>m1>>d1>>p_id15>>p_id18>>y2>>m2>>d2>>validyear;
CNewID a(p_name,y1,m1,d1,p_id15,p_id18,y2,m2,d2,validyear);
a.print();
}
return 0;
}