为什么我这里用const int N = 1e7后不能输入,而1e6却是正常的
#include
#include
using namespace std;
const int N=1e6+10;
int main()
{
char x,ch[N];
int k,a=0,b=0;
while(cin>>x){
if(x=='E')break;
ch[k++]=x;
}
for(int i=0;iif(ch[i]=='W')a++;
else if(ch[i]=='L')b++;
if(max(a,b)>=11&&fabs(a-b)>=2){
cout<":"<0;
}
}
cout<":"<puts("\n");
a=b=0;
for(int i=0;iif(ch[i]=='W')a++;
else if(ch[i]=='L')b++;
if(max(a,b)>=21&&fabs(a-b)>=2){
cout<":"<0;
}
}
cout<":"<return 0;
}
const int N=1e7一直无法输入,改成1e6后就正常了,是不是const有使用边界?
是的,const int 的使用边界是受限于编译器和计算机系统的,具体取决于系统的内存大小和编译器对常量表达式的支持情况。
综上所述,在使用 const int 常量时,应该注意其取值不能超过编译器和计算机系统所能支持的范围。
ch[N] 有限制,改成动态数组就。
char *ch = new char[N];