解题思路:
注意事项:
参考代码:
#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语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:2498 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:640 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)for循环浏览:1178 |
C语言程序设计教程(第三版)课后习题9.8 (Java代码)浏览:1674 |
人见人爱A+B (C语言代码)浏览:664 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:702 |
简单的for循环浏览:1498 |
C语言程序设计教程(第三版)课后习题6.8 (C++代码)浏览:614 |
P1000 (C语言代码)浏览:911 |
字符逆序 (C语言代码)浏览:506 |