小票输入输出(结构体)
时间限制1s
内存限制128MB
题目描述
现在人的消费习惯大多是刷卡消费,商家会通过POS机回执一个小票,包含商家名称、终端号、操作员、发卡方、有效期、卡号、交易时间、消费金额等信息,把商家信息定义为一个Struct结构,按照要求输出相应的格式小票。
输入
第一行输入消费次数(刷卡次数)
第二行依次输入小票包含的各种属性,最大长度不超过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
输出样例:Name: TianHong
Terminal: 00001 operator: 01
Card Issuers: CCB Validity: 21/06
CardNumber: 6029********5678
Traded: 2016/3/13
Costs: $1000.00Name: 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 receipt {
string Name;
string Terminal;
string Operator;
string Card_Issuers;
string Validity;
string CardNumber;
string Traded;
string Costs;
};
int main() {
int t = 0;
cin >> t;
receipt a;
while (t-- ) {
cin >> a.Name;
cin >> a.Terminal;
cin >> a.Operator;
cin >> a.Card_Issuers;
cin >> a.Validity ;
cin >> a.CardNumber;
cin >> a.Traded;
cin >> a.Costs;
for (int i = 4; i < 12; i++)
a.CardNumber[i] = '*';
cout << "Name: " << a.Name << endl;
cout << "Terminal: " << a.Terminal;
cout << " operator: " << a.Operator << endl;
cout << "Card Issuers: " << a.Card_Issuers ;
cout << " Validity: " << a.Validity << endl;
cout << "CardNumber: " << a.CardNumber << endl;
cout << "Traded: " << a.Traded << endl;
cout << "Costs: $" << a.Costs << endl;
cout << endl;
}
return 0;
}