pat编译错误,error: passing 'const record' as 'this' argument of 'bool record::operat
In file included from /usr/include/c++/4.7/algorithm:63:0,from a.cpp:9:
/usr/include/c++/4.7/bits/stl_algo.h: In instantiation of '_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, const _Tp&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<record*, std::vector<record> >; _Tp = record]':
/usr/include/c++/4.7/bits/stl_algo.h:2309:70: required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<record*, std::vector<record> >]'
/usr/include/c++/4.7/bits/stl_algo.h:2340:54: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<record*, std::vector<record> >; _Size = long int]'
/usr/include/c++/4.7/bits/stl_algo.h:5476:4: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<record*, std::vector<record> >]'
a.cpp:66:45: required from here
/usr/include/c++/4.7/bits/stl_algo.h:2271:4: error: passing 'const record' as 'this' argument of 'bool record::operator<(record)' discards qualifiers [-fpermissive]
这是pat的甲级1016题的一次提交,在vs2013上可以运行,上面是编译错误的信息。
代码:
//#include "stdafx.h" 这个在pat上去掉的
#include <time.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
struct record{
time_t t;
bool z;
bool valid = 0;
bool operator < (const record bsl){
return t < bsl.t;
};
bool operator > (const record bsl){
return t > bsl.t;
};
};
int main(void)
{
int cents[24], cday = 0;
int N;
int amount = 0, i, mon;
string mgz, shj, zht;
time_t rlt = time(NULL);
tm * bdt,* bdt2;
map<string, vector<record>> yonghu;
map<string, int> jifei;
record jilu;
map<string, vector<record>>::iterator ddq;
vector<record>::iterator diedai, diedai2;
bdt = localtime(&rlt);
for (i = 0; i < 24; i++){
cin >> cents[i];
cday += cents[i];
}
cin >> N;
for (i = 0; i < N; i++){
int date,hour, min;
cin >> mgz;
scanf("%d:%d:%d:%d", &mon, &date, &hour, &min);
cin >> zht;
bdt->tm_sec = 30;
bdt->tm_mon = mon;
bdt->tm_mday = date;
bdt->tm_hour = hour;
bdt->tm_min = min;
if (zht == "on-line"){
jilu.z = true;
bdt->tm_sec = 20;
}
else{
jilu.z = false;
bdt->tm_sec = 0;
}
rlt = mktime(bdt);
jilu.t = rlt;
yonghu[mgz].push_back(jilu);
jifei[mgz] = 0;
}
for (ddq = yonghu.begin(); ddq != yonghu.end(); ddq++){ // 各记录按时间顺序排序
sort(ddq->second.begin(),ddq->second.end());
}
for (ddq = yonghu.begin(); ddq != yonghu.end(); ddq++){
cout << ddq->first << " " << setfill('0') << setw(2) << mon << endl;
for (diedai = ddq->second.begin(); diedai != ddq->second.end();diedai++){
diedai2 = diedai + 1;
if (diedai2 == ddq->second.end())
break;
if ((diedai->z == true) && (diedai2->z == false)){
diedai->valid = true;
diedai2->valid = true;
int dy[2], hr[2], mn[2], charge[2];
bdt = localtime(&(diedai->t));
dy[0] = bdt->tm_mday; hr[0] = bdt->tm_hour; mn[0] = bdt->tm_min;
bdt2 = localtime(&(diedai2->t));
dy[1] = bdt2->tm_mday; hr[1] = bdt2->tm_hour; mn[1] = bdt2->tm_min;
printf("%02d:%02d:%02d ", dy[0], hr[0], mn[0]);
printf("%02d:%02d:%02d ", dy[1], hr[1], mn[1]);
for (int k = 0; k < 2; k++){
charge[k] = cday*dy[k] * 60;
for (int temp = 0; temp < hr[k]; temp++)
charge[k] += cents[temp] * 60;
charge[k] += cents[hr[k]] * mn[k];
}
amount = charge[1] - charge[0];
i = 1 + difftime(diedai2->t, diedai->t) / 60;
cout << i << " $" <<fixed<< setprecision(2) << amount / 100.0 << endl;
jifei[ddq->first] += amount;
diedai++;
}
}
cout << "Total amount: $" <<fixed<< setprecision(2) << jifei[ddq->first] / 100.0 << endl;
}
return 0;
}
求助,看不懂错误原因