1.题目:
Problem Description
LPRJ小工厂是刚兴起不久的标准工厂,每天早上八点开始上班,每天工作八小时,但是由于LPRJ小工厂近来员工懈怠于工作,经常迟到,于是经理LP决定用考勤打卡机来记录员工的上班时间,经理为了整顿一下员工的上班态度,决定员工每迟到半小时将扣除10元的工资,若不迟到员工每天的工资有80元,计算每位员工在今天可获得的工资。(要求用类完成)
Input
输入数据有多组,每组第一行输入一个整数T,代表接下去有T行员工测试数据
每位员工的资料包含工号,姓名,打卡时间(hh:mm);
Output
输出每位员工的信息以及当天可获得的工资。
Sample Input
3
12078 LP 07:45
12080 shik 08:00
12012 junl 08:31
Sample Output
12078 LP 07:45 80
12080 shik 08:00 80
12012 junl 08:31 60
有两种方法,一种是用整型的来接收时间,一种是用字符串的来接收。
2.代码一:
#include <iostream>
#include <cstring>
using namespace std;
class LPRJ
{
private:
char id[21], name[21], temp[2];
int hour, minute, money;
public:
LPRJ(char a[], char b[], int c, char d[], int e);
int count();
void show();
};
LPRJ::LPRJ(char a[], char b[], int c, char d[], int e)
{
strcpy(id, a);
strcpy(name, b);
hour = c;
minute = e;
}
int LPRJ::count()
{
int totle = hour * 60 + minute;
if (totle <= 8 * 60)
money = 80;
else if (totle > 11 * 60 + 30)
money = 0;
else {
if (minute == 0)
money = 80 - (hour - 8) * 20;
else {
int i, sum = 0, a;
for (i = 8; i < 12; i++) {
if (minute > 0 && minute <= 30)
a = 1;
else if (minute > 30 && minute <= 59)
a = 2;
}
sum += (hour - 8) * 2 + a;
money = 80 - sum * 10;
}
}
return money;
}
void LPRJ::show()
{
printf("%s %s %02d:%02d %d\n", id, name, hour, minute, count());
}
int main()
{
int hour, minute, t;
char id[21], name[21], temp[2] = ":";
while (cin >> t) {
while (t--) {
scanf("%s %s %d:%d", id, name, &hour, &minute);
LPRJ w(id, name, hour, temp, minute);
w.show();
}
}
return 0;
}
代码二:
#include<iostream>
#include<string>
using namespace std;
class Time
{
private:
int id;
string a;
string b;
int m;
public:
Time(int i, string aa, string bb, int mm): id(i), a(aa), b(bb), m(mm)
{}
void set() {
int t;
t = ((b[0] - '0') * 10 + (b[1] - '0')) * 60 + (b[3] - '0') * 10 + b[4] - '0' - 480;
if (t > 0) {
if (t % 30 == 0) m -= 10 * (t / 30);
else m -= 10 * (t / 30 + 1);
if (m < 0) m = 0;
}
}
void show() {
cout << id << ' ' << a << ' ' << b << ' ' << m << endl;
}
};
int main()
{
int t, id, i; string aa, bb;
while (scanf("%d", &t) != EOF) {
for (i = 0; i < t; i++) {
cin >> id >> aa >> bb;
Time w(id, aa, bb, 80);
w.set();
w.show();
}
}
return 0;
}