黑色星期五 帮看看为什么提交错误. C++
发布网友
发布时间:2022-10-15 05:54
我来回答
共2个回答
热心网友
时间:2023-10-05 12:04
#include<iostream>
using namespace std;
int main()
{
int w;
while(cin>>w)
{
w--; //added
int flag1=0;
int months,days;
bool m[12];
for(int j=0;j<12;j++)
m[j]=true;
bool flag= true;
for(months=0;months<=11;months++)
{
switch(months)
{
case 0:
days=31;
break;
case 1:
days=29;
break;
case 2:
days=31;
break;
case 3:
days=30;
break;
case 4:
days=31;
break;
case 5:
days=30;
break;
case 6:
days=31;
break;
case 7:
days=31;
break;
case 8:
days=30;
break;
case 9:
days=31;
break;
case 10:
days=30;
break;
case 11:
days=31;
break;
}
for(int now=1; now<=days;now++)
{
if(now==13&&w==4) //modified
m[months]=false;
w++;
w = w%7;
//注意这里,不能写 w=(w++)%7;可以换成 w=(++w)%7或上面的,最好分开写容易不出错
}
}
for(int i=0;i<12;i++)
{
if(m[i]==false&&flag1==0)
{
cout<<i+1;
flag=false;
flag1=1;
}
else if(m[i]==false&&flag1!=0)
{
cout<<" "<<i+1;
}
}
if(flag==true)
cout<<"NULL";
cout<<endl;
}
return 0;
}
原因:星期是从1-7,而你用的 %7的值是0-6
所以你应该把所有的值减一来匹配。希望你能通过
不能写 w=(w++)%7; 由于w=(w++)你这里面相当于 w=w%7
可以换成 w=(++w)%7或上面的,最好分开写容易不出错,不过再问吧
热心网友
时间:2023-10-05 12:04
#include <iostream>
using namespace std;
class Run
{
private:
int w;
public:
void xqw()
{
int n=1;//判断是否输出null
cout<<"请输入w的值"<<endl;
cin>>w;
if(w+(13-1)%7==5)
{cout<<"1"<<" ";n=0;}
if(w+(13+31-1)%7==5)
{cout<<"2"<<" ";n=0;}
if(w+(13+31+29-1)%7==5)
{cout<<"3"<<" ";n=0;}
if(w+(13+31+29+31-1)%7==5)
{cout<<"4"<<" ";n=0;}
if(w+(13+31+29+31+30-1)%7==5)
{cout<<"5"<<" ";n=0;}
if(w+(13+31+29+31+30+31-1)%7==5)
{cout<<"6"<<" ";n=0;}
if(w+(13+31+29+31+30+31+30-1)%7==5)
{cout<<"7"<<" ";n=0;}
if(w+(13+31+29+31+30+31+30+31-1)%7==5)
{cout<<"8"<<" ";n=0;}
if(w+(13+31+29+31+30+31+30+31+31-1)%7==5)
{cout<<"9"<<" ";n=0;}
if(w+(13+31+29+31+30+31+30+31+31+30-1)%7==5)
{cout<<"10"<<" ";n=0;}
if(w+(13+31+29+31+30+31+30+31+31+30+31-1)%7==5)
{cout<<"11"<<" ";n=0;}
if(w+(13+31+29+31+30+31+30+31+31+30+31+30-1)%7==5)
{cout<<"12"<<endl<<" ";n=0;}
if(n)
cout<<"NULL"<<endl;
}
};
void main()
{
int n;
cout<<"请输入你想输入的组数"<<endl;
cin>>n;
Run r;
for(int i=0;i<n;i++)
{
r.xqw();
}
}