70分,不知为什么2,5,8组数据出错
查看原帖
70分,不知为什么2,5,8组数据出错
1134154
CXRunfree楼主2023/10/14 15:58

使用了to_string方法进行字符串按位比对,理论上不可能错呀?

#include <iostream>
#include <string> 
using namespace std;
int main(){
	int n;char x;
	int count_x=0;
	cin>>n>>x;
	for(int i=0;i<=n;i++){
	string s=to_string(i);
	for (int j=0;j<s.size();j++){
		if (s[j]==x) count_x++;
	}}
	cout<<count_x;
	return 0;
}
  
2023/10/14 15:58
加载中...