@[CXRunfree](/user/1134154) *试计算在区间 **1** 到 n 的所有整数中*
by Argvchs @ 2023-10-14 15:59:58
@[Argvchs](/user/533270) 哦哦,把前后条件看串了
by CXRunfree @ 2023-10-14 16:03:34
但是有一种可能,测试样例2,5,8的x是0,题目中的范围是1~n,如果你的代码中遍历的是0~n,那么count_x就会多1,样例自然WA了.\
AC code:
```cpp
#include<iostream>
using namespace std;
int n,x;
int fun(int n,int x)
{
int cnt = 0;
while(n /= 10 != 0)
{
if (n % 10 == x)
{
cnt++;
}
n /= 10;
}
return cnt;
}
int main()
{
int ans = 0;
cin >> n >> x;
for (int i = 1;i <= n;i++)
{
ans += fun(i,x);
}
cout << ans << endl;
return 0;
}
```
by Jacky_luogu @ 2023-10-15 11:20:29