解题思路:
注意事项:
参考代码:
#include <iostream> #include <cstdio> #include <cstring> #include <vector> using namespace std; const int N = 105, mod = 20123; char str[N]; int get(vector<int> &numbers, int l, int r) { vector<int> dividend; for (int i = r; i >= l; --i) dividend.push_back(numbers[i]); int t = 0; for (int i = dividend.size()-1; i >= 0; --i) { dividend[i] += t * 10; t = dividend[i] % mod; dividend[i] /= mod; while (dividend.size() && !dividend.back()) dividend.pop_back(); } return t; } int expmod(int a, int b) { int res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } int dp(int u) { int n = strlen(str); vector<int> numbers; for (int i = 0; i < n; ++i) numbers.push_back(str[i]-'0'); int res = 0; for (int i = 0; i < n; ++i) { if (i) res = (res + get(numbers, 0, i-1) * expmod(10, n-i-1)) % mod; if (numbers[i] == u) res = (res + get(numbers, i+1, n-1) + 1) % mod; else if (numbers[i] > u) res = (res + expmod(10, n-i-1)) % mod; } return res; } int main() { scanf("%s", str); printf("%d", (dp(1) + dp(2)) % mod); return 0; }
0.0分
0 人评分
#include <stdio.h> int number(int n) { int count1 = 0; int count2 = 0; for (int i = 1; i <= n; i++) { int num = i; while (num) { if (num%10==1 ) { count1++; } else if (num % 10 == 2) { count2++; } num /= 10; } } return count1 + count2; } int main() { int n; scanf_s("%d",&n); int count=number(n); printf("%d", count); }
#include <stdio.h> int number(int n) { int count1 = 0; int count2 = 0; for (int i = 100; i <= n; i++) { int num = i; while (num) { if (num%10==1 ) { count1++; } else if (num % 10 == 2) { count2++; } num /= 10; } } return count1 + count2; } int main() { int n; scanf_s("%d",&n); int count=number(n); printf("%d", count); }
秋 2024-04-07 19:38:43 |
自我感觉没有错误有没有大佬指点一下
C语言程序设计教程(第三版)课后习题11.11 (C语言代码)浏览:768 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:564 |
Hello, world! (C语言代码)浏览:1196 |
字符串输入输出函数 (Java代码)浏览:1437 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:664 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:460 |
完数 (C语言代码)浏览:685 |
K-进制数 (C语言描述,蓝桥杯)浏览:925 |
1017题解浏览:581 |
A+B for Input-Output Practice (C语言代码)浏览:458 |