#15717: 為什麼會RE啦...


vm0u831@gmail.com (:D D)


自己用就沒問題,上傳卻RE...求救到底是哪裡有問題...

 

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

int main()
{
string a,b;
int cou=0;
while(cin>>a){

for(int i=0;i<a.length();i++){
int c=a.length();
b[i]=a[c-1-i]; 
}
for(int i=0;i<a.length();i++){
if(b[i]==a[i]) {
cou = 1;
}else{
cou = 0;
break;
}
}
if(cou==1){
cout<<"yes"<<endl;
}else{
cout<<"no"<<endl;
}

}

return 0;
}

#15721: Re:為什麼會RE啦...


OwO310659 (OwO)


你的 字串b 一開始宣告的時候預設會是空字串(""),
所以你在操作 b[i]=a[c-1-i]; 時,
b[i] 有可能會存取到其它的記憶體位置而導致RE。

以上希望有幫助到你~