AtCoder Beginner Contest 438_A##题解

WACODE
`
include <bits/stdc++.h>
using namespace std;
using ll = long long;
int d,f;
void solve()
{
cin>>d>>f;//一开始是我自己跟那个样例写出来的发现WA了一半,然后跑去请教AI,说我漏了一种情况即f-1<n,如果还是不懂的话,就是当d=10,f为3,n=3时,我这个程序是错的
int n = d%7;
int x = f - n;
cout<<x<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>d>>f;
solve();
return 0;
}
`
/*所以我们还要考虑这个情况即f-1<n
比赛日的星期 (f-1) 在下一年第一天的星期 (n) 之前
我们需要绕到下个周期去找
所以差值应该是:(f-1) + 7 - n*/
ACcode
`
include <bits/stdc++.h>
using namespace std;
int main()
{
int d,f;
cin>>d>>f;
int n = d%7;//设为星期0-6
int x = (f - 1 + 7 - n)%7 + 1;//后面记得加回1
cout<<x<<endl;
return 0;
}
`

浙公网安备 33010602011771号