Official

B - Subscribers Editorial by en_translator


Truncating \(10^d\)s and less digits is equivalent to

  • replacing \(N\) with \(N-M\), where \(M\) is the remainder when \(N\) is divided by \(10^{d+1}\); or
  • treating \(N\) as a string and replace \(4\)-th and later characters with 0.

Therefore, codes like these are accepted.

Sample code 1

#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n < 1000) cout << n << '\n';
	if (1000 <= n && n <= 9999) cout << n - n % 10 << '\n';
	if (10000 <= n && n <= 99999) cout << n - n % 100 << '\n';
	if (100000 <= n && n <= 999999) cout << n - n % 1000 << '\n';
	if (1000000 <= n && n <= 9999999) cout << n - n % 10000 << '\n';
	if (10000000 <= n && n <= 99999999) cout << n - n % 100000 << '\n';
	if (100000000 <= n && n <= 999999999) cout << n - n % 1000000 << '\n';
}

Sample code 2

#include <iostream>
using namespace std;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };

int main() {
	int n;
	cin >> n;
	if (n < 1000) cout << n << '\n';
	for (int i = 1; i <= 6; i++) if (ten(i + 2) <= n && n < ten(i + 3)) cout << n - n % ten(i) << '\n';
}

Sample code 3

#include <iostream>
#include <string>
using namespace std;

int main() {
	string s;
	cin >> s;
	if (s.size() <= 3) cout << s << '\n';
	else cout << s.substr(0, 3) << string(s.size() - 3, '0') << '\n';
}

posted:
last update: