#4787: 為什麼會RE


sam574 (liu)


因為已經不只第一次發生個問題了 

真的很想了解為什麼有時候在dev c跑程式ok

但是在這裡run卻RE

希望可以教教我  感恩

#include <iostream>
#include <cstring>

using namespace std;

int main(void)
{
    int a=0,j=0,count=0;
    char str1[999],str2[999];
   
    while(cin>>str1)
    {
          a=strlen(str1)-1;
         
          for(int i=a;i>=0;i--)
          {
                  str2[i]=str1[j];
                  j++;
          }
          j=0;
         
          for(int x=0;x<=a;x++)
          {
                  if(str1[x]==str2[x])
                  count++;
                  else
                  count--;
          }
          if(count==a+1)
          cout<<"yes"<<endl;
          else
          cout<<"no"<<endl;
         
          for(int k=0;k<=999;k++)
          {
                  str1[k]=0;
                  str2[k]=0;
          }
          count=0;
    }
    
 
    return EXIT_SUCCESS;
}

 

 

#4788: Re:為什麼會RE


popular10347 (ICPC// 哪時能唸到高等演算法T^T)


因為已經不只第一次發生個問題了 

真的很想了解為什麼有時候在dev c跑程式ok

但是在這裡run卻RE

希望可以教教我  感恩

#include
#include

using namespace std;

int main(void)
{
    int a=0,j=0,count=0;
    char str1[999],str2[999];
   
    while(cin>>str1)
    {
          a=strlen(str1)-1;
         
          for(int i=a;i>=0;i--)
          {
                  str2[i]=str1[j];
                  j++;
          }
          j=0;
         
          for(int x=0;x<=a;x++)
          {
                  if(str1[x]==str2[x])
                  count++;
                  else
                  count--;
          }
          if(count==a+1)
          cout<<"yes"<          else
          cout<<"no"<         
          for(int k=0;k<=999;k++)
          {
                  str1[k]=0;
                  str2[k]=0;
          }
          count=0;
    }
    
 
    return EXIT_SUCCESS;
}

 

 

你的陣列大小太小了

題目不是說<1000

所以必須要開到1000 (多一格是要存'\0')

#4792: Re:為什麼會RE


sam574 (liu)


因為已經不只第一次發生個問題了 

真的很想了解為什麼有時候在dev c跑程式ok

但是在這裡run卻RE

希望可以教教我  感恩

#include
#include

using namespace std;

int main(void)
{
    int a=0,j=0,count=0;
    char str1[999],str2[999];
   
    while(cin>>str1)
    {
          a=strlen(str1)-1;
         
          for(int i=a;i>=0;i--)
          {
                  str2[i]=str1[j];
                  j++;
          }
          j=0;
         
          for(int x=0;x<=a;x++)
          {
                  if(str1[x]==str2[x])
                  count++;
                  else
                  count--;
          }
          if(count==a+1)
          cout<<"yes"<          else
          cout<<"no"<         
          for(int k=0;k<=999;k++)
          {
                  str1[k]=0;
                  str2[k]=0;
          }
          count=0;
    }
    
 
    return EXIT_SUCCESS;
}

 

 

你的陣列大小太小了

題目不是說<1000

所以必須要開到1000 (多一格是要存'\0')

感謝 原來是這個原因 以後會再多加注意 謝謝