浙大PAT甲级-1016

Phone Bills

1.更改文件输入输出方式:

freopen("input.txt","r",stdin);

freopen("output.txt","w",stdout);

******//中间代码正常cin,cout

fclose(stdin);

fclose(stdout);

2.vector删除某一项:

删除v[i]:

v.erase(v.begin()+i);

【注】:删除某项后其后面的项会自动向前补上,所以要是在遍历v时删除一项记得要将标记回退一项(i--)

3.C++字符串比较函数compare:

s1.compare(s2);

返回正数:s1>s2;

返回零:s1=s2;

返回负数:s1


#include 
#include 
#include 
#include 
#include 
using namespace std;
int cents[24],n;

struct Record{
    string name;
    int month;
    int day;
    int hour;
    int minute;
    string status;
};
bool cmp(Record r1, Record r2){
    if(r1.name.compare(r2.name)==0){
        if(r1.dayr2.day)
            return 0;
        else{
            if(r1.hourr2.hour)
                return 0;
            else{
                if(r1.minute0){
        return 0;
    }else{
        return 1;
    }
}
int tim(Record r1,Record r2){//r1到r2时间差
    return r2.day*24*60+r2.hour*60+r2.minute-r1.day*24*60-r1.hour*60-r1.minute;
}
int callAllDay(){//打了一整天
    int t=0;
    for(int i=0;i<24;i++){
        t+=cents[i]*60;
    }
    return t;
}
int callNtoM(int n,int m){//从n点整打到m点整
    int t=0;
    for(int i=n;ir1.hour){
            total+=callNtoM(r1.hour+1,r2.hour);
            total+=(60-r1.minute)*cents[r1.hour]+r2.minute*cents[r2.hour];
        }else{
            total+=(r2.minute-r1.minute)*cents[r1.hour];
        }
    }
    return total/100.0;
}
int main()
{
    int i;
    vector r;
    //freopen("input.txt","r",stdin);//重置输入流,文件输入
    for(i=0;i<24;i++)
        cin>>cents[i];

    cin>>n;
    for(i=0;i>n;
        scanf("%d:%d:%d:%d",&mo,&d,&h,&mi);
        cin>>s;
        Record re;
        re.name=n;
        re.day=d;
        re.hour=h;
        re.minute=mi;
        re.month=mo;
        re.status=s;
        r.push_back(re);
    }
    sort(r.begin(),r.end(),cmp);//根据用户名和时间排序

    string sn=r[0].name;
    bool valid=0;

    for(i=0;i


你可能感兴趣的:(浙大PAT甲级练习题)