ccf crontab 5分求错

#include<iostream>
using namespace std;
#include<cstring>
#include<cmath>
#include<fstream>
#include<algorithm>
#include<vector>

struct qj{
    int a;
    int b;
    qj(int aa,int bb){
        a= aa;
        b=bb;
    }
};
int cnum=0;
struct Command{
    vector <qj> min;
    vector <qj> hour;
    vector <qj> day;
    vector <qj> mon;
    vector <qj> weekday;
    string comm;
    int bh;
};
Command c[1000];

int strtonum(string s){
    int tmp=0;
    int num = s.length();
    for(int i=0;i<num;i++){
        tmp=tmp+(s[i]-'0')*pow(10,num-i-1);
    }
    return tmp;
}

struct Time{
    int year,mon,day,hour,min;
    Time(int y,int m,int d,int h,int mi){
        year = y;
        mon = m;
        day = d;
        hour = h;
        min = mi;
    }
};

bool comparetime(Time t2,Time t1){
    if(t1.year>t2.year) return true;
    else if(t1.year<t2.year) return false;
    else{
        if(t1.mon>t2.mon) return true;
        else if(t1.mon<t2.mon) return false;
        else{
            if(t1.day>t2.day) return true;
            else if(t1.day<t2.day) return false;
            else{
                if(t1.hour>t2.hour) return true;
                else if(t1.hour<t2.hour) return false;
                else{
                    if(t1.min>t2.min) return true;
                    else if(t1.min<=t2.min) return false;
                    
                }
            }
        }
    }
}

int xingqiji(Time t){
 //蔡勒公式,计算这天是周几,公式只适合于1582年10月15日之后的情形  
  int year = t.year;    
    int month = t.mon;
    int day = t.day;
    int m,d=day;  
    if(month<3)  
    {  
        m=month+12;  
        year--;  
    }  
    else m=month;  
    int c=year/100;   
    int y=year%100;  
    int w=(c/4)-2*c+(y+y/4)+(13*(m+1)/5)+day-1;  
    return (w%7+7)%7;  //返回0代表周日   
 
}
void shuchu(Time t){
    string tmp="";
    int tm = t.year/1000;
    tmp+= '0'+tm;
    tm = t.year/100-tm*10;
    tmp+= '0'+tm;
    tm = t.year/10-tm*10-t.year/1000*100;
    tmp+='0'+tm;
    tmp+= '0'+t.year%10;

    if(t.mon<10){
        tmp+= "0";
        tmp+= '0'+t.mon;
    }
    else{
        tmp+= '0'+t.mon/10;
        tmp += '0'+t.mon%10;
    }
    if(t.day<10){
        tmp+= "0";
        tmp+= '0'+ t.day;
    }
    else {
        tmp+= '0'+t.day/10;
        tmp += '0'+t.day%10;
        
    }
    if(t.hour<10){
        tmp+= "0";
        tmp+= '0'+ t.hour;
    }
    else{
        tmp+= '0'+t.hour/10;
        tmp += '0'+t.hour%10;
        
    }
    if(t.min<10){
        tmp+= "0";
        tmp+= '0'+ t.min;
    }
    else{
        tmp+= '0'+t.min/10;
        tmp += '0'+t.min%10;
        
    }
    cout<<tmp;
}
void chazhao(Time t){
    bool flagmo=false,flagd=false,flagh=false,flagm=false,flagw=false;
    
    int xq = xingqiji(t);
//    cout<<xq<<endl;
    for(int i=0;i<cnum;i++){
        if(c[i].mon[0].a==-1) {
            flagmo =true;
        }
        else{
            for(int j=0;j<c[i].mon.size();j++){
                if(c[i].mon[j].a<=t.mon&&c[i].mon[j].b>=t.mon){
                    flagmo = true;
                    break;
                }
            }
        }
            
        if(c[i].day[0].a==-1) {
            flagd =true;
        }
        else{
            for(int j=0;j<c[i].day.size();j++){
                if(c[i].day[j].a<=t.day&&c[i].day[j].b>=t.day){
                    flagd = true;
                    break;
                }
            }
        }            
        if(c[i].hour[0].a==-1){
            flagh = true;
        }
        else{
            for(int j=0;j<c[i].hour.size();j++){
                if(c[i].hour[j].a<=t.hour&&c[i].hour[j].b>=t.hour){
                    flagh = true;
                    break;
                }
            }
        }            
        if(c[i].min[0].a==-1) {
            flagm =true;
        }
        else{
            for(int j=0;j<c[i].min.size();j++){
                if(c[i].min[j].a<=t.min&&c[i].min[j].b>=t.min){
                    flagm = true;
                    break;
                }
            }
        }            
        if(c[i].weekday[0].a==-1) {
            flagw =true;
        }
        else{
            for(int j=0;j<c[i].weekday.size();j++){
                //cout<<c[i].weekday[j].a<<" "<<c[i].weekday[j].b<<endl;
                if(c[i].weekday[j].a<=xq&&c[i].weekday[j].b>=xq){
                    flagw = true;
                    break;
                }
            }
        }            
        if(flagmo&&flagd&&flagh&&flagm&&flagw){
            shuchu(t);
            cout<<" "<<c[i].comm<<endl;
            
        }
        flagmo=false;flagd=false;flagh=false;flagm=false;flagw=false;
    }
    
}

void shijian(string b,string e){

    string tmp;
    string y[2],m[2],d[2],h[2],min[2];
    y[0] = b.substr(0,4);
    m[0] = b.substr(4,2);
    d[0] = b.substr(6,2);
    h[0] = b.substr(8,2);
    min[0] = b.substr(10,2);
    y[1] = e.substr(0,4);
    m[1] = e.substr(4,2);
    d[1] = e.substr(6,2);
    h[1] = e.substr(8,2);
    min[1] = e.substr(10,2);
    Time begin = Time(strtonum(y[0]),strtonum(m[0]),strtonum(d[0]),strtonum(h[0]),strtonum(min[0]));
    Time end = Time(strtonum(y[1]),strtonum(m[1]),strtonum(d[1]),strtonum(h[1]),strtonum(min[1]));
    chazhao(begin);
    while(comparetime(begin,end)){
        begin.min++;
        if(!comparetime(begin,end)) break;
        if(begin.min==60){
            begin.min =0 ;
            begin.hour++;
            if(begin.hour==24){
                begin.hour=0;
                begin.day++;
                if(begin.day==31){
                    if(begin.mon==1||begin.mon==3||begin.mon==5||begin.mon==7||begin.mon==8||begin.mon==10||begin.mon==12){
                        if(begin.mon==12){
                            begin.mon = 1;
                            begin.year++;
                            begin.day=1;
                        }
                        else{
                            begin.mon++;
                            begin.day=1;
                        }
                    }
                }
                else if(begin.day==30){
                    if(begin.mon==4||begin.mon==6||begin.mon==9||begin.mon==11){                    
                        begin.day = 1;
                        begin.mon++;                        
                    }
                }
                else if(begin.day==29&&begin.mon==2){
                    if((begin.year%100==0&&begin.year%400==0)||(begin.year%100!=0&&begin.year%4==0)){  //能被100以及400整除的闰年
                        begin.day==1;
                        begin.mon++;
                    }
                }
                else if(begin.day==28&&begin.mon==2){
                    if((begin.year%100==0&&begin.year%400==0)||(begin.year%100!=0&&begin.year%4==0)){  //能被100以及400整除的闰年
                        ;
                    }                
                    else{
                        begin.day = 1;
                        begin.mon++;
                    }    
                }
            }
        }
        chazhao(begin);
    }    
}
string tobig(string s){    //传进来的不能用
    string t = s;
    for(int i=0;i<t.length();i++){
        if(t[i]>='a'&&t[i]<='z'){
            t[i]=t[i]+'A'-'a';
        }
    }
    return t;
}
int strtomon(string t){
    string s = tobig(t);
    if(s=="JAN") return 1;
    if(s=="FEB") return 2;
    if(s=="MAR") return 3;
    if(s=="APR") return 4;
    if(s=="MAY") return 5;
    if(s=="JUN") return 6;
    if(s=="JUL") return 7;
    if(s=="AUG") return 8;
    if(s=="SEP") return 9;
    if(s=="OCT") return 10;
    if(s=="NOV") return 11;
    if(s=="DEC") return 12;    
}

int strtoxq(string t){
    string s = tobig(t);
    //cout<<s<<endl;
    if(s=="MON") return 1;
    if(s=="TUE") return 2;
    if(s=="WED") return 3;
    if(s=="THU") return 4;
    if(s=="FRI") return 5;
    if(s=="SAT") return 6;
    if(s=="SUN") return 0;
}
void strtocomm(string m,string h,string d,string mo,string w,string comm){
    if(mo[0]=='*'){
        c[cnum].mon.push_back(qj(-1,100));
    }
    else{
        string t="";
    //    string s[100];
        int n=0,min,max;
        int l = mo.length();
        bool flagj = false;
        for(int i=0;i<l;i++){
            if(mo[i]==','){
                if(!flagj){ //如果前面没有减号
                    if(t[0]<'0'||t[0]>'9'){
                        int tmp = strtomon(t);
                        c[cnum].mon.push_back(qj(tmp,tmp));
                    }
                    else{
                        int tmp = strtonum(t);
                        c[cnum].mon.push_back(qj(tmp,tmp));
                    }
                    t="";                    
                }
                else{ //如果前面有减号
                    flagj = false;
                    if(t[0]<'0'||t[0]>'9') max = strtomon(t);
                    else max = strtonum(t);
                    t = "";
                    c[cnum].mon.push_back(qj(min,max));
                    
                }
            }
            else if(mo[i]=='-'){
                flagj = true;
                if(t[0]<'0'||t[0]>'9') min = strtomon(t);
                else min = strtonum(t);
                t="";
            }
            else{
                t+=mo[i];    
            }
        }
            if(t.length()) {
                if(flagj){
                    flagj = false;
                    if(t[0]<'0'||t[0]>'9') max = strtomon(t);
                    else max = strtonum(t);
                    t = "";
                    c[cnum].mon.push_back(qj(min,max));                            
                }
                else{
                    if(t[0]<'0'||t[0]>'9'){
                        int tmp=strtomon(t);
                        c[cnum].mon.push_back(qj(tmp,tmp));
                    }
                    else{
                        int tmp=strtonum(t);
                        c[cnum].mon.push_back(qj(tmp,tmp));        
                    }         
                }
            }
    }
    
    if(h[0]=='*'){
        c[cnum].hour.push_back(qj(-1,100));
    }
    else{
        string t="";
    //    string s[100];
        int n=0,min,max;
        int l = h.length();
        bool flagj = false;
        for(int i=0;i<l;i++){
            if(h[i]==','){
                if(!flagj){ //如果前面没有减号
                    int tmp = strtonum(t);
                    c[cnum].hour.push_back(qj(tmp,tmp));
                    t="";                    
                }
                else{ //如果前面有减号
                    flagj = false;
                    max = strtonum(t);
                    t = "";
                    c[cnum].hour.push_back(qj(min,max));
                }
            }
            else if(h[i]=='-'){
                flagj = true;
                min = strtonum(t);
                t="";
            }
            else{
                t+=h[i];    
            }
        }
        if(t.length()){
            if(flagj){
                flagj = false;
                max = strtonum(t);
                t = "";
                c[cnum].hour.push_back(qj(min,max));                    
                    
            }
            else{
                int tmp=strtonum(t);
                c[cnum].hour.push_back(qj(tmp,tmp));                
            }            
        }
        
        
    }
    if(d[0]=='*'){
        c[cnum].day.push_back(qj(-1,100));
    }
    else{
        string t="";
    //    string s[100];
        int n=0,min,max;
        int l = d.length();
        bool flagj = false;
        for(int i=0;i<l;i++){
            if(d[i]==','){
                if(!flagj){ //如果前面没有减号
                    int tmp = strtonum(t);
                    c[cnum].day.push_back(qj(tmp,tmp));
                    t="";                    
                }
                else{ //如果前面有减号
                    flagj = false;
                    max = strtonum(t);
                    t = "";
                    c[cnum].day.push_back(qj(min,max));
                    
                }
            }
            else if(d[i]=='-'){
                flagj = true;
                min = strtonum(t);
                t="";
            }
            else{
                t+=d[i];    
            }
        }
        if(t.length()){
            if(flagj){
                flagj = false;
                max = strtonum(t);
                t = "";
                c[cnum].day.push_back(qj(min,max));                    
                    
            }
            else{
                int tmp=strtonum(t);
                c[cnum].day.push_back(qj(tmp,tmp));                
            }            
        }         
    
    }
    if(m[0]=='*'){
        c[cnum].min.push_back(qj(-1,100));
    }
    else{
        string t="";
    //    string s[100];
        int n=0,min,max;
        int l = m.length();
        bool flagj = false;
        for(int i=0;i<l;i++){
            if(m[i]==','){
                if(!flagj){ //如果前面没有减号
                    int tmp = strtonum(t);
                    c[cnum].min.push_back(qj(tmp,tmp));
                    t="";                    
                }
                else{ //如果前面有减号
                    flagj = false;
                    max = strtonum(t);
                    t = "";
                    c[cnum].min.push_back(qj(min,max));
                }
            }
            else if(m[i]=='-'){
                flagj = true;
                min = strtonum(t);
                t="";
            }
            else{
                t+=m[i];
                
            }
        }
        if(t.length()){
            if(flagj){
                flagj = false;
                max = strtonum(t);
                t = "";
                c[cnum].min.push_back(qj(min,max));                    
                    
            }
            else{
                int tmp=strtonum(t);
                c[cnum].min.push_back(qj(tmp,tmp));                
            }            
        }
    }
    
    if(w[0]=='*'){
        c[cnum].weekday.push_back(qj(-1,100));
    }
    else{
        string t="";
    //    string s[100];
        int n=0,min,max;
        int l = w.length();
        bool flagj = false;
        for(int i=0;i<l;i++){
            if(w[i]==','){
                if(!flagj){ //如果前面没有减号
                    if(t[0]<'0'||t[0]>'9'){
                        int tmp=strtoxq(t);
                        //cout<<t<<tmp<<endl;
                        c[cnum].weekday.push_back(qj(tmp,tmp));
                    }
                    else{
                        int tmp=strtonum(t);
                        c[cnum].weekday.push_back(qj(tmp,tmp));
                    }
                    t="";                    
                }
                else{ //如果前面有减号
                    flagj = false;
                    if(t[0]<'0'||t[0]>'9') max = strtoxq(t);
                    else max = strtonum(t);
                    t = "";
                    c[cnum].weekday.push_back(qj(min,max));
                }

            }
            else if(w[i]=='-'){
                flagj = true;
                if(t[0]<'0'||t[0]>'9') min = strtoxq(t);
                else min = strtonum(t);
                t="";
            }
            else{
                t+=w[i];
            }
        }
        if(t.length()) {
            if(flagj){
                flagj = false;
                if(t[0]<'0'||t[0]>'9') max = strtoxq(t);
                else max = strtonum(t);
                t = "";
            
                c[cnum].weekday.push_back(qj(min,max));                    
                    
            }
            else{
                if(t[0]<'0'||t[0]>'9'){
                    int tmp=strtoxq(t);
                //    cout<<t<<tmp<<endl;
                    c[cnum].weekday.push_back(qj(tmp,tmp));
                }
                else{
                    int tmp=strtonum(t);
                    c[cnum].weekday.push_back(qj(tmp,tmp));                
                }
            }
        }
    }
    
    c[cnum++].comm = comm;
}
int main(){
    ifstream cin("in.txt");
    int n;
    string b,e;
    cin>>n>>b>>e;
    string min,hour,day,mon,weekday,comm;
    for(int i=0;i<n;i++){
        cin>>min>>hour>>day>>mon>>weekday>>comm;
        
        strtocomm(min,hour,day,mon,weekday,comm);    
    }
    shijian(b,e);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值