c++,2、5、8WA,救救孩子

P1980 [NOIP2013 普及组] 计数问题

``` #include<bits/stdc++.h> using namespace std; int main() { int n, x,count; cin >> n >> x; count = 0; for (int i = 1; i <= n; i++) { int m = 1; while (i / m >= 1) { if (i / m % 10 == x) { count++; } m *= 10; } } cout << count << endl; return 0; } ``` 无需特判;
by chenzixuan49 @ 2024-03-30 16:43:00


``` # include<bits/stdc++.h> using namespace std; int main() { int n, x, m, l; cin >> n >> x; m = 0; for (int w = 1 ; w <= n ; w++) { l = w; while(1 <= l) { if (l % 10 == x) { m++; } l /= 10; } } cout << m; return 0; } ``` 这样做会更好理解;
by chenzixuan49 @ 2024-03-30 16:44:04


|