WHY
查看原帖
WHY
1372558
paulyan楼主2024/9/29 16:50

我没用递归,用字符串来处理。结果...... 没编译错误,但运行是这个样子: terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid

测试点全RE 代码

#include <iostream> 
#include <string>
using namespace std;
int main(){
	string n,k,cnt=0;
	cin>>n>>k;
	int n2=n.size();
	for(int i=0;i<n2;i++){
		cnt=n[i];
		if(cnt==k){
		    cout<<n[i];	
		    return 0;
		}
	}
	return 0;
}
2024/9/29 16:50
加载中...