这也能过?
查看原帖
这也能过?
1314007
Zhall_Dreamy楼主2024/12/17 20:21

我刚刚提交,发现我的代码的bool数组只开了26,然后读入时ch没-'a',然后这能不越界?

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int val=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		val*=10,val+=ch-'0',ch=getchar();
	return val*f;
}
inline void write(const int& val)
{
	if(val<0)
	{
		putchar('-'),write(-val);
		return;
	}
	if(val>9) write(val/10);
	putchar(val%10+'0');
}
bool f[26];
char ch;
signed main()
{
	while((ch=getchar())!='\n')
	{
		if(f[ch])//没减'a'
		{
			puts("no");
			return 0;
		}
		else f[ch]=true;
	}
	puts("yes");
	return 0;
}
2024/12/17 20:21
加载中...