Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 计划在一周中的bth c日获得一个月_C++ - Fatal编程技术网

C++ 计划在一周中的bth c日获得一个月

C++ 计划在一周中的bth c日获得一个月,c++,C++,例如,获取2000年至2015年10月第三个星期五的日期。 我知道1850-1-1是星期二 我在OJ上得了80分(低于最高分)。我不知道臭虫在哪里。请帮我找到问题。我试了很长时间,但没能解决这个问题。下面是我的代码: #include <iostream> #include <string> #include <sstream> using namespace std; int daysFrom[250]; bool year_check(int year);

例如,获取2000年至2015年10月第三个星期五的日期。 我知道1850-1-1是星期二

我在OJ上得了80分(低于最高分)。我不知道臭虫在哪里。请帮我找到问题。我试了很长时间,但没能解决这个问题。下面是我的代码:

#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int daysFrom[250];
bool year_check(int year);
string int2String(int a);
int main(){
    unsigned int month2days[13];
    month2days[0]=0;
    month2days[1]=31;
    month2days[2]=0;
    month2days[3]=31;
    month2days[4]=30;
    month2days[5]=31;
    month2days[6]=30;
    month2days[7]=31;
    month2days[8]=31;
    month2days[9]=30;
    month2days[10]=31;
    month2days[11]=30;
    month2days[12]=31;
    int a;
    cin>>a;
    int b;
    cin>>b;
    int c;
    cin>>c;
    int y1;
    cin>>y1;
    int y2;
    cin>>y2;
    daysFrom[0]=0;
    for(int i=1;i<250;i++){
        int year=1850+i;
        if(year_check(year-1)){
            daysFrom[i]=daysFrom[i-1]+366;
        }else{
            daysFrom[i]=daysFrom[i-1]+365;
        }
    }
    for(int yearP=y1;yearP<=y2;yearP++){
        unsigned int days=daysFrom[yearP-1850];
        for(int monthP=1;monthP<a;monthP++){
            if(monthP==2){
                if(year_check(yearP)){
                    days+=29;
                }else{
                    days+=28;
                }
            }else{
                days+=month2days[monthP];
            }
        }
        int weekPos=days%7;
        weekPos=(weekPos+2)%7;
        int dis=0;
        if(c<weekPos){
            dis=7-weekPos+c+1+(b-1)*7;
        }else{
            dis=c-weekPos+1+(b-1)*7;
        }
        if(a==2){
            if(year_check(yearP)){
                if(dis>29){
                    cout<<"none"<<endl;
                }else{
                    cout<<yearP<<"/"<<int2String(a)<<"/"<<int2String(dis)<<endl;
                }
            }else{
                if(dis>28){
                    cout<<"none"<<endl;
                }else{
                    cout<<yearP<<"/"<<int2String(a)<<"/"<<int2String(dis)<<endl;
                }
            }
        }else{
            if(dis>month2days[a]){
                cout<<"none"<<endl;
            }else{
                cout<<yearP<<"/"<<int2String(a)<<"/"<<int2String(dis)<<endl;
            }
        }
    }
    return 0;
}
bool year_check(int year){
    if(year%400==0){
        return true;
    }else{
        if(year%4==0&&year%100!=0){
            return true;
        }
    }
    return false;
}
string int2String(int a){
    switch(a){
    case 1:
        return "01";
    case 2:
        return "02";
    case 3:
        return "03";
    case 4:
        return "04";
    case 5:
        return "05";
    case 6:
        return "06";
    case 7:
        return "07";
    case 8:
        return "08";
    case 9:
        return "09";
    default:
        stringstream str;
        str<<a;
        return str.str();
    }
}
#包括
#包括
#包括
使用名称空间std;
从[250]开始的整数天;
布尔年检查(整数年);
字符串int2String(inta);
int main(){
未签署的整数月2日[13];
月2天[0]=0;
月2天[1]=31;
月2天[2]=0;
月2天[3]=31;
月2天[4]=30;
月2天[5]=31天;
月2天[6]=30;
月2天[7]=31;
月2天[8]=31天;
月2天[9]=30;
每月2天[10]=31天;
月2天[11]=30;
月2天[12]=31;
INTA;
cin>>a;
int b;
cin>>b;
INTC;
cin>>c;
int y1;
cin>>y1;
int y2;
cin>>y2;
从[0]开始的天数=0;
对于(inti=1;i我得到了它。
问题是

weekPos=(weekPos+2)%7;

星期天是0。实际上是7。

当使用调试器检查代码时,您特别注意到了什么?我的意思是,我在本地机器上测试了代码,得到了正确的ans。但是oj系统测试结果显示,十个测试中有两个测试失败。我找不到特定的测试,也不知道错误所在。不要浪费您的时间在线判断s、 我们至少不能在这里告诉你,为什么你会得到一个WA。引擎的内部工作没有透露。还要确保测试所有闰年条件的边缘情况。我发现了问题。谢谢。