if you are reading this blog, hi.
I have some problems with the "Div. 7" problem:
Here is the official code (from BledDest):
Codet = int(input())
for i in range(t):
n = int(input())
if n % 7 == 0:
print(n)
else:
ans = -1
for j in range(10):
if (n - n % 10 + j) % 7 == 0:
ans = n - n % 10 + j
print(ans)
And here is my c++ code when I try to translate from Python $$$\rightarrow$$$ C++:
Codeint n;
cin >> n;
if (n % 7 == 0) cout << n << '\n';
else
{
int res = -1;
for (int j = 0; j <= 10; j++)
{
if ((n - n % 10 + j) % 7 == 0)
{
res = n - n % 10 + j;
}
}
cout << res << '\n';
But, when I submit my C++ code, it gets the wrong answer on test 2 (on test case 52), you can check: 145516095
If you understand the reason why you can comment under this blog. Thank you very much for your help!
Полный текст и комментарии »