#include<bits/stdc++.h>
using namespace std;
int spilt (int x, int pre, int post) {
string p = "";
p.append(to_string(x));
return stoi(p.substr(pre, post));
}
int main() {
int ans = 0;
int k;
cin >> k;
for (int i = 10000; i <= 30000; i++) {
if((spilt(i, 0, 3) % k == 0) && (spilt(i, 1, 3) % k == 0) && (spilt(i, 2, 4) % k == 0)){
cout << i << endl; // << ' ' << spilt(i, 0, 3) << ' ' << spilt(i, 1, 3) << ' ' << spilt(i, 2, 4)
ans++;
}
}
if(ans == 0){
cout << "No" << endl;
}
return 0;
}
原来写的是
#include<bits/stdc++.h>
using namespace std;
int spilt (int x, int pre, int post) {
string p = "";
p.append(to_string(x));
return stoi(p.substr(pre, post));
}
int main() {
int ans = 0;
int k;
cin >> k;
for (int i = 10000; i <= 30000; i++) {
if((spilt(i, 0, 2) % k == 0) && (spilt(i, 1, 3) % k == 0) && (spilt(i, 2, 4) % k == 0)){
cout << i << endl; // << ' ' << spilt(i, 0, 2) << ' ' << spilt(i, 1, 3) << ' ' << spilt(i, 2, 4)
ans++;
}
}
if(ans == 0){
cout << "No" << endl;
}
return 0;
}
第十五行不同是spilt(i, 0, 2)但是为什么要写spilt(i, 0, 3)?取三位不应该是spilt(i, 0, 2)返回子串(0, 1, 2)这三个吗,为什么要写spilt(i, 0, 3),蒟蒻不懂,有没有大佬说下原因,orz