萌新求助,我这样写有什么问题?为什么每次find函数返回值都是-1???
  • 板块P1765 手机
  • 楼主lht20090314
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/7/5 22:09
  • 上次更新2023/11/3 11:25:00
查看原帖
萌新求助,我这样写有什么问题?为什么每次find函数返回值都是-1???
728458
lht20090314楼主2023/7/5 22:09

萌新求助,请问我这样写有什么问题?为什么每次find函数返回值都是-1???

代码:

#include<cstdio>
#include<string>
using namespace std;

int main()
{
	string three = "abcdefghijklmnotuv", four = "pqrswxyz";
	char a;
	int cnt = 0;
	while(a = getchar() != EOF)
	{
		if(three.find(a) != -1)
			cnt += (three.find(a) % 3);
		else if(four.find(a) != -1)
			cnt += four.find(a) % 4;
		else
			cnt++;
	}
	printf("%d", cnt);
	
	return 0;
}

有哪位大佬可以帮忙解答一下,谢谢!

2023/7/5 22:09
加载中...