题目描述
现在人的消费习惯大多是刷卡消费,商家会通过POS机回执一个小票,
包含商家名称、终端号、操作员、发卡方、有效期、卡号、交易时间、消费金额等信息,
把商家信息定义为一个结构结构,按照要求输出相应的格式小票。
输入
第一行输入消费次数(刷卡次数)
第二行依次输入小票包含的各种属性,最大长度不超过30.
第三行与第二行类似,以此类推。。。
输出
根据输入信息,依次输出各次刷卡信息
输入样例1
2
TianHong 00001 01 CCB 21/06 6029071012345678 2016/3/13 1000.00
Cindy 00002 02 CCB 21/07 6029071055558888 2015/3/13 50.00
输出样例1
Name: TianHong
Terminal: 00001 operator: 01
Card Issuers: CCB Validity: 21/06
CardNumber: 6029********5678
Traded: 2016/3/13
Costs: $1000.00
Name: Cindy
Terminal: 00002 operator: 02
Card Issuers: CCB Validity: 21/07
CardNumber: 6029********8888
Traded: 2015/3/13
Costs: $50.00
#include<iostream>
#include<string>
using namespace std;
struct card
{
string name;
string terminal;
string Operator;
string Card_Issuers;
string Validity;
string CardNumber;
string Traded;
string Costs;
};
int main()
{
int t;
cin >> t;
for (int i=0; i < t; i++)
{
card c;
cin >> c.name >> c.terminal >> c.Operator >> c.Card_Issuers;
cin >> c.Validity >> c.CardNumber >> c.Traded >> c.Costs;
cout << "Name: " << c.name << endl;
cout << "Terminal: " << c.terminal << " operator: " << c.Operator << endl;
cout << "Card Issuers: " << c.Card_Issuers << " Validity: " << c.Validity << endl;
int len = c.CardNumber.size();
char* star = new char[len-7]; //创建自由数组 长度比密码段长度减去前后四个数字还长一
for (int j = 0; j <= len-8; j++) // 个单位 用于存放结束字符;
{
if (j!=len-8)
{
star[j] = '*';
}
else
{
star[j] = '\0';
}
}
cout << "CardNumber: "<< c.CardNumber.substr(0,4); //.substr 用于提取string中特定
//长度的字符串。
for (int j = 0; j < len-8; j++)
{
cout << star[j];
}
cout << c.CardNumber.substr(len - 4, len) << endl;
cout << "Traded: " << c.Traded<< endl;
cout << "Costs: $" << c.Costs << endl;
cout << endl;
}
return 0;
}