警示后人
查看原帖
警示后人
1005749
xzz_0611楼主2024/7/10 17:46

有的数据有前导 00,所以如下的代码会 WA:

#include<iostream>
#include<algorithm>
using namespace std;
signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	string str,arr;
	cin>>str;
	transform(str.begin(),str.end(),str.begin(),::tolower);
	int ans=0,cnt=0;
	bool flag=true;
	while(cin>>arr) {
		transform(arr.begin(),arr.end(),arr.begin(),::tolower);
		if(arr==str) {
			++ans;
			flag=false;
		}
		if(flag) cnt+=arr.size()+1;
	}
	if(ans) cout<<ans<<" "<<cnt;
	else cout<<-1;
	return 0;
}
2024/7/10 17:46
加载中...