为什么i必须小于S.size-1呢
2025-09-04 19:24:11
发布于:上海
乐乐:
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
string S,s;
for(int i=1;i<=t;i++){
int n;
cin>>n;
S=" ";
for(int i=1;i<=n;i++){
cin>>s;
S+=s;
}
bool f=true;
for(int i=1;i<S.size()-1;i++){
if(S[i]>S[i+1]){
f=false;
break;
}
}
if(f==true){
cout<<1<<endl;
}else{
cout<<0<<endl;
}
}
return 0;
}
为什么i必须小于S.size-1呢
全部评论 1
因为你遍历到了
S[i+1]
,如果 的话第 个下标就越界了2天前 来自 广东
0
有帮助,赞一个