【关于测试点1】输入第一行末尾有\r
  • 板块B2118 验证子串
  • 楼主bingxw
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/7/7 23:15
  • 上次更新2023/11/3 11:07:09
查看原帖
【关于测试点1】输入第一行末尾有\r
2860
bingxw楼主2023/7/7 23:15

使用cin可以过,但是用getline就会WA第一个点。 我试了一下把第一行末尾的\r去掉,AC了。

#include<iostream>
using namespace std;
int main()
{
	string s1,s2;
	getline(cin,s1);
	getline(cin,s2); //cin>>s1>>s2;
	if(s1[s1.length()-1]=='\r') s1.pop_back();
	if(s2.find(s1)!=s2.npos) cout << s1 << " is substring of " << s2 << endl;
	else if(s1.find(s2)!=s1.npos) cout << s2 << " is substring of " << s1 << endl;
	else cout << "No substring" << endl;
	return 0;
}
2023/7/7 23:15
加载中...