#2977: 我一直過不了 我已經爬過文了,我除了避掉空白,我也避掉其他符號了,但來是跟我說WA


fpgr9621 (練習用)


#include <cstring>
#include<iostream>
using namespace std;
int main()
{
 int i ;
 char c[9999];
 while(cin.getline(c,9999)){
  int word=0,x=0;    
  for(i=0;i<strlen(c);i++){
   if((c[i]>=65&&c[i]<=90)||(c[i]>=97&&c[i]<=122)&&x==0){
    word++;
    x=1;
   }
   else if((c[i]<=65||c[i]>=90)&&(c[i]<=97||c[i]>=122)&&x==1)
    x=0;
  }
  cout << word << endl;
 }
 return 0;
}

我已經爬過文了,我除了避掉空白,我也避掉其他符號了,但來是跟我說WA

#2987: Re:我一直過不了 我已經爬過文了,我除了避掉空白,我也避掉其他符號了,但來是跟我說WA


chchwy (Matt)


 

#include
#include
using namespace std;
int main()
{
 int i ;
 char c[9999];
 while(cin.getline(c,9999)){
  int word=0,x=0;    
  for(i=0;i
   if((c[i]>=65&&c[i]<=90)||(c[i]>=97&&c[i]<=122)&&x==0){
    word++;
    x=1;
   }
   else if((c[i]<=65||c[i]>=90)&&(c[i]<=97||c[i]>=122)&&x==1)
    x=0;
  }
  cout << word << endl;
 }
 return 0;
}

我已經爬過文了,我除了避掉空白,我也避掉其他符號了,但來是跟我說WA

你可能要注意一下 && 跟 || 的優先順序關係