The question is not difficult, but the input and output data is large and the format is large. You need to think about it and pay attention to it. It took a lot of time, but it was a bit rewarding. First, the string type can only use cin, but not scanf or printf. To use printf, you can only use printf ("% s", str. c_str ()). If ":" is included in the input, getchar () is required (). In printf, % is added less for the last % 02d, and the error message is always out of bounds. Be careful. We found that the pat test data has a critical condition, for example, 01: 02: 14: 58-01: 02: 14: 59, if I used to only consider the time plus head and tail plus center, an error would occur. In addition, It is worth noting that It is guaranteed that at least one call is well formed red in the input. only ensure that at least one correct match is made for each input, and that each user has a correct match. Therefore, a user may not have a correct match. In this case, do not output any user information. I am still too weak ~ AC code: [cpp] // 1016 # include <iostream> # include <string> # include <cstdlib> using namespace std; const int NUM = 1005; struct record {string name; int dd, hh, mm; string status; int total;} rec [NUM]; struct call {int s; int e; double m ;} cal [NUM]; int toll [26]; int sumToll; int cmp (const void * a, const void * B) {record * x = (record *); record * y = (record *) B; // if (x-> name = y-> name & x-> dd = y-> dd & x-> Hh = y-> hh) // return x-> mm-y-> mm; // if (x-> name = y-> name & x-> dd = y-> dd) // return x-> hh-y-> hh; // if (x-> name = y-> name) // return x-> dd-y-> dd; // return x-> name <y-> name; if (x-> name = y-> name) return x-> total-y-> total; if (x-> name <y-> name) return-1; else return 1;} int find (int start, int end) {int ans = 0, I; if (rec [start]. dd <rec [end]. dd) {for (I = rec [start]. hh + 1; I <24; I ++) {ans + = toll [I] * 60;} For (I = 0; I <rec [end]. hh; I ++) ans + = toll [I] * 60; ans + = (60-rec [start]. mm) * toll [rec [start]. hh]; ans + = rec [end]. mm * toll [rec [end]. hh]; ans + = (rec [end]. dd-rec [start]. dd-1) * sumToll * 60;} else if (rec [start]. dd = rec [end]. dd) {if (rec [end]. hh> rec [start]. hh) {for (I = rec [start]. hh + 1; I <rec [end]. hh; I ++) ans + = toll [I] * 60; ans + = (60-rec [start]. mm) * toll [rec [start]. hh]; ans + = rec [end]. mm * toll [rec [end]. hh];} else {ans + = (Rec [end]. mm-rec [start]. mm) * toll [rec [end]. hh] ;}} else ans =-1; return ans;} int main () {int n, I, j, month; freopen ("C: \ Documents and Settings \ Administrator \ Desktop \ input.txt "," r ", stdin); sumToll = 0; for (I = 0; I <24; I ++) {cin> toll [I]; sumToll + = toll [I];} cin> n; for (I = 0; I <n; I ++) {// The string type can only use cin, but not scanf or printf. If printf is used, only printf ("% s", str. c_str () // cin> rec [I]. name> month> ":"> rec [I]. dd> ":"> rec [I ]. Hh> ":"> rec [I]. mm> rec [I]. status; cin> rec [I]. name; cin> month; getchar (); cin> rec [I]. dd; getchar (); cin> rec [I]. hh; getchar (); cin> rec [I]. mm; cin> rec [I]. status; rec [I]. total = rec [I]. dd * 60*24 + rec [I]. hh * 60 + rec [I]. mm;} qsort (rec, n, sizeof (rec [0]), cmp); string str = ""; int start, end, flag = 0; int theSame = 0; rec [n]. name = ""; double money = 0.0f; int minute; double sum = 0.0f; int index = 0; for (I = 0; I <n; I ++) {If (str! = Rec [I]. name) {str = rec [I]. name; flag = 0; theSame = 0; index = 0;} else theSame = 1; // same as the previous if (rec [I]. status [1] = 'n') {// on start = I; flag = 1; // 1 indicates that on already exists.} if (theSame = 1 & flag = 1 & rec [I]. status [1] = 'F') {// off is the same end = I as the previous one; flag = 0; // 0 indicates that it is off, you can start money = find (start, end) again; money = money/100.0; sum + = money; cal [index]. s = start; cal [index]. e = end; cal [index]. m = money; // printf ("% 02d: % 02d: % 02d % 02d: % 02d: % 02d: % 02d % D $ % 0.2lf \ n ", rec [start]. dd, rec [start]. hh, rec [start]. mm, rec [end]. dd, rec [end]. hh, rec [end]. mm, minute, money); index ++;} if (rec [I]. name! = Rec [I + 1]. name & index! = 0) {printf ("% s % 02d \ n", rec [I]. name. c_str (), month); for (j = 0; j <index; j ++) {start = cal [j]. s; end = cal [j]. e; money = cal [j]. m; minute = rec [end]. total-rec [start]. total; printf ("% 02d: % 02d: % 02d % 02d: % 02d: % 02d % d $ % 0.2lf \ n", rec [start]. dd, rec [start]. hh, rec [start]. mm, rec [end]. dd, rec [end]. hh, rec [end]. mm, minute, money);} www.2cto.com printf ("Total amount: $ %. 2lf \ n ", sum); sum = 0.0f; index = 0 ;}// printf (" \ n "); // for (I = 0; I <n; I ++) {// printf ("% s % 02d: % 02d: % 02d: % 02d % s \ n", rec [I]. name. c_str (), month, rec [I]. dd, rec [I]. hh, rec [I]. mm, rec [I]. status. c_str (); //} return 0 ;}