https://ac.nowcoder.com/acm/contest/5944/A
太坑了,有空一定把它做出来
//真坑,就有一条,我加上输出调试的时候是对的,但是交的时候就变成了错的 #include <cmath> #include <cstring> #include <iostream> using namespace std; typedef long long ll; ll t; int main(){ cin >> t; while (t -- ){ ll n; ll a[10], b[10]; cin >> n; memset(a, 0, sizeof 0); memset(b, 0, sizeof 0); //记录为每一个数的第i位后为0的数,如i = 2,n = 321, 则a[2] = 320; for (int i = 1; i <= 10; i ++ ){ a[i] = n / pow(10, i - 1); } //记录输入的n是几位数 int cnt = 0, t = n, m = n; while (t){ t /= 10; cnt ++; } //记录每一位的数是几 for (int i = 1; i <= m; i ++ ){ b[i] = m % 10; m /= 10; } //求结果 ll ans = 0; for (int i = cnt; i >= 1; i -- ){ if (b[i] > 7) ans += ((a[i + 1] + 1) * pow(10, i - 1)); else if (b[i] == 7){ ans += (a[i + 1] * pow(10, i - 1)) + (n - a[i] * pow(10, i - 1)) + 1; //cout << n << endl; //cout << a[i] << endl; //cout << pow(10, i - 1) << endl; } else ans += a[i + 1] * pow(10, i - 1); cout << ans << ' ' << a[i + 1] << ' ' << a[i] << ' ' << pow(10, i - 1) << endl; } cout << ans << endl; } return 0; }
// #include<iostream> #include<math.h> #include<string> using namespace std; int count7(int number, int d) { int pownum = pow(10, d); int gaowei = number / (pownum * 10); int digit = (number / pownum) % 10; if (digit < 7) { return gaowei * pownum; }else if (digit == 7) { return gaowei * pownum + number % pownum + 1; }else { return (gaowei + 1) * pownum; } } int main() { int t; cin >> t; while (t -- ){ int number; cin >> number; int count = 0; string str; str = to_string(number); for (int i = 0; i < str.size(); i++) { count += count7(number, i); } cout << count<< endl; } return 0; }