#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
vector<int> table() {
//0-10^10
vector<int> table(10);
for (int i = 0; i < 10; ++i) {
if (i < 2) {
table[i] = 0;
}
else {
table[i] = table[i-1] + table[i - 1] * 8 + (int)pow(10, i - 2);
}
}
return table;
}
int main() {
vector<int> t = table();
/*
for (int i = 0; i < t.size(); ++i) {
cout << "<" << i << ">:" << t[i] << endl;
}*/
long num;
while (cin >> num) {
long num_begin = num;
vector<int> n;
while (num > 0) {
n.push_back((int)(num % 10));
num = num / 10;
}
vector<int> n_res;//逆置
for (int i = n.size() - 1; i >= 0; --i) {
n_res.push_back(n[i]);
}
long sum = 0;//带4的数字总数
for (int i = n_res.size() - 1; i >= 0; --i) {
while (n[i] > 0) {
if (n[i] == 4) {
//cout << "4444" << endl;
sum += pow(10, i);
}
else {
sum += t[i + 1];
//cout << "i:" << i << " "<<"sum:"<<sum<<endl;
}
--n[i];
}
}
//cout << "4_sum:" << sum << endl;
cout << num_begin - sum << endl;
}
}
Terrible_4
于 2024-07-11 23:04:00 首次发布