#496: 一直RE


trewsla (trewsla)


以下為code

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
 char a[1000];  
 while (cin.get()!= EOF)
   { 
     cin.get(a,1000);
     int b=1; 
     for (int i=0;i<=(strlen(a)-1);i++)
       {
         if (a[i]>122 || a[i]<65 || (a[i]<97 && a[i]>90)) 
           {
             if (((i!=0) && (i!= (strlen(a)-1))) && ((a[i-1]<122
                   && a[i-1]>97) || (a[i-1]>65 && a[i-1]<90)))
                {
                 b=b+1;
                 }
             else if (i== (strlen(a)-1))
                  b=b-1;   
           }
       }
    cout << b <<endl;  
   }
return 0;
}  

使用DEV-C++可以正常執行

不過在這就一直RE

請問各位大大 有哪邊需要改進的

謝謝大家

 

#497: Re:一直RE


POOHccc ()


以下為code

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
 char a[1000];  
 while (cin.get()!= EOF)
   { 
     cin.get(a,1000);
     int b=1; 
     for (int i=0;i<=(strlen(a)-1);i++)
       {
         if (a[i]>122 || a[i]<65 || (a[i]<97 && a[i]>90)) 
           {
             if (((i!=0) && (i!= (strlen(a)-1))) && ((a[i-1]<122
                   && a[i-1]>97) || (a[i-1]>65 && a[i-1]<90)))
                {
                 b=b+1;
                 }
             else if (i== (strlen(a)-1))
                  b=b-1;   
           }
       }
    cout << b <<endl;  
   }
return 0;
}  

使用DEV-C++可以正常執行

不過在這就一直RE

請問各位大大 有哪邊需要改進的

謝謝大家

 



我猜可能測資長度>1000,所以造成記憶體使用不正常

改用string、或是字元陣列開大一點試試 

#5869: Re:一直RE


mofom123 (Hong0308)


 

我也是 RE ...

可以也順便看看我的麻...? 我有照你做的 開很大的陣列...

 

#include <stdio.h>

#include <stdlib.h>

#include <strings.h>

 

main(){

 

    char in[100000];

    int many;

    char *p;

    

    for(;;){

            

        if(gets(in)==NULL) break;

        

        p=strtok(in," \n");

        

        for(many=0;;){

            

            if(*p>=97 && *p<=122)                                 

            ++many;

            if(*p>=65 && *p<=90)                                 

            ++many;

            if(p==NULL) break;

            p=strtok(NULL," \n");

            if(p==NULL) break;

        }

        printf("%d\n",many);

    }

 

}