下面给大家两段代码
1st
#include <bits/stdc++.h>
#define int long long
using namespace std;
int s(int a) {
int sum = 0;
while (a) {
sum += a % 10;
a /= 10;
}
return sum;
}
signed main()
{
int n;
int x;
cin >> n;
while (n --) {
cin >> x;
int t = s(x);
if(t % 7 == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
2nd
#include <bits/stdc++.h>
#define int long long
using namespace std;
int s(int a) {
int sum = 0;
while (a) {
sum += a % 10;
a /= 10;
}
return sum;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
int x;
cin >> n;
while (n --) {
cin >> x;
int t = s(x);
if(t % 7 == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
可见,上面两段代码除了io方式,其他都一样,但是(样例这里取)输出却不一样,这是为什么?