#3403: 如何讀取空白字串


saitor362320 (Kira Yamato)


本題有個測資是"aB3caB3   "

最後一個字元是空白字元

char a[50]

while(scanf("%s",a)!=EOF)

會讀不到

請問一下該如何讀取?

#3404: Re:如何讀取空白字串


example (學姊)


本題有個測資是"aB3caB3   "

最後一個字元是空白字元

char a[50]

while(scanf("%s",a)!=EOF)

會讀不到

請問一下該如何讀取?

 那就是一次讀整行的 gets()

 寫成 while( gets(a) != 0 )

#3405: Re:如何讀取空白字串


saitor362320 (Kira Yamato)


本題有個測資是"aB3caB3   "

最後一個字元是空白字元

char a[50]

while(scanf("%s",a)!=EOF)

會讀不到

請問一下該如何讀取?

 那就是一次讀整行的 gets()

 寫成 while( gets(a) != 0 )

原來如此~~感謝學姐微笑!

太久沒用差點忘了XDD

#3406: Re:如何讀取空白字串


saitor362320 (Kira Yamato)


本題有個測資是"aB3caB3   "

最後一個字元是空白字元

char a[50]

while(scanf("%s",a)!=EOF)

會讀不到

請問一下該如何讀取?

 那就是一次讀整行的 gets()

 寫成 while( gets(a) != 0 )

原來如此~~感謝學姐微笑!

太久沒用差點忘了XDD


不過本題其實有兩個陣列a,b

本來是寫while(scanf("%s%s",a,b)!=EOF)

改成while(gets(a)!=0&&get(b)!=0)後

會出現RE

應該要怎麼寫才好呢?

#3409: Re:如何讀取空白字串


linishan (L)


 


不過本題其實有兩個陣列a,b

本來是寫while(scanf("%s%s",a,b)!=EOF)

改成while(gets(a)!=0&&get(b)!=0)後

會出現RE

應該要怎麼寫才好呢?


while(gets(a))
{
  gets(b);

#3410: Re:如何讀取空白字串


example (學姊)


本題有個測資是"aB3caB3   "

最後一個字元是空白字元

char a[50]

while(scanf("%s",a)!=EOF)

會讀不到

請問一下該如何讀取?

 那就是一次讀整行的 gets()

 寫成 while( gets(a) != 0 )

原來如此~~感謝學姐微笑!

太久沒用差點忘了XDD


不過本題其實有兩個陣列a,b

本來是寫while(scanf("%s%s",a,b)!=EOF)

改成while(gets(a)!=0&&get(b)!=0)後

會出現RE

應該要怎麼寫才好呢?

 我是這樣寫沒錯阿@@

 附上宣告

 char password[101], check[101];

 while( gets(password) != 0 && gets(check) != 0 ) {

     ...

 }

#3414: Re:如何讀取空白字串


saitor362320 (Kira Yamato)


本題有個測資是"aB3caB3   "

最後一個字元是空白字元

char a[50]

while(scanf("%s",a)!=EOF)

會讀不到

請問一下該如何讀取?

 那就是一次讀整行的 gets()

 寫成 while( gets(a) != 0 )

原來如此~~感謝學姐微笑!

太久沒用差點忘了XDD


不過本題其實有兩個陣列a,b

本來是寫while(scanf("%s%s",a,b)!=EOF)

改成while(gets(a)!=0&&get(b)!=0)後

會出現RE

應該要怎麼寫才好呢?

 我是這樣寫沒錯阿@@

 附上宣告

 char password[101], check[101];

 while( gets(password) != 0 && gets(check) != 0 ) {

     ...

 }

還是不行耶

可能是因為我有用function

不過改掉function也是RE...

//===========

#include<stdio.h>
#include<string.h>
#define SIZE_Z 13
int unsame(const char A[SIZE_Z],const char B[SIZE_Z])
{int i;
if(strcmp(A,B)!=0){printf("Password settings are not consistent.\n");
 return 0;
}
 for(i=0;i<strlen(A);i++){
  if(A[i]!=B[i]){printf("Password settings are not consistent.\n");
   return 0;
  }
 }
 return 1;
}
int leth(const char A[SIZE_Z])
{if(strlen(A)>=8&&strlen(A)<=12)
   return 1;
 else {
  printf("Password should contain 8 to 12 characters.\n");
  return 0;   
 }

}
int big(const char A[SIZE_Z])
{int i;
 for(i=0;i<strlen(A);i++){
  if(A[i]>=65&&A[i]<=90){
   
   return 1;
  }
 }
 printf("Password should contain at least one upper-case alphabetical character.\n");
 return 0;
}
int small(const char A[SIZE_Z])
{int i;
 for(i=0;i<strlen(A);i++){
  if(A[i]>=97&&A[i]<=122){
   
   return 1;
  }
 }
 printf("Password should contain at least one lower-case alphabetical character.\n");
 return 0;


}
int math(const char A[SIZE_Z])
{int i;
 for(i=0;i<strlen(A);i++){
  if(A[i]>=48&&A[i]<=57){
   
   return 1;
  }
 }
 printf("Password should contain at least one number.\n");
 return 0;

}
int mark(const char A[SIZE_Z])
{int i;
 for(i=0;i<strlen(A);i++){
  if(A[i]>=32&&A[i]<=33||
     A[i]>=35&&A[i]<=38||
     A[i]>=40&&A[i]<=47||
     A[i]>=58&&A[i]<=64||
     A[i]>=91&&A[i]<=96||
     A[i]>=123&&A[i]<=126||
     A[i]==41382||
     A[i]==41384
   ){
   
   return 1;
  }
 }
 printf("Password should contain at least one special character.\n");
 return 0;

}
int symmetric(const char A[SIZE_Z])
{int i;
 int j=strlen(A);
 int k;
 for(i=0,k=1;i<strlen(A);i++,k++){
  if(A[i]!=A[j-k])return 1;
 }
 printf("Symmetric password is not allowed.\n");
 return 0;
}
int circular(const char A[SIZE_Z])
{int i;
 int j=1;
 int hk=1;
 int string_long=strlen(A);
 int lenth=0;
 int remain_lenth;
 int sai;

 for(i=3;i<6;i++){
  if(A[i]==A[0]&&A[i+1]==A[1]){
  lenth=i;
  remain_lenth=strlen(A)-lenth;
  hk=0;
  break;
   }
 }
 


if(hk)return 1;
  
 sai=string_long%lenth;
  
 if(sai==0){
 for(i,j=1;i+1<strlen(A);i++,j++){
  
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==1){
  if(A[string_long-1]!=A[0])return 1;
  for(i,j=1;i+1<strlen(A)-1;i++,j++){
  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==2){
 if(A[string_long-1]!=A[1]&&A[string_long-2]!=A[0])return 1;
  for(i,j=1;i+1<strlen(A)-2;i++,j++){
  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==3){
  if(A[string_long-1]!=A[2]&&A[string_long-2]!=A[1]&&A[string_long-3]!=A[0])return 1;
  for(i,j=1;i+1<strlen(A)-3;i++,j++){
  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==4){
  
  if(A[string_long-1]!=A[3]&&A[string_long-2]!=A[2]&&A[string_long-3]!=A[1]&&A[string_long-4]!=A[0])return 1;
  for(i,j=1;i+1<strlen(A)-4;i++,j++){
  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==5){
  
 if(A[string_long-1]!=A[4]&&A[string_long-2]!=A[3]&&A[string_long-3]!=A[2]&&A[string_long-4]!=A[1]&&A[string_long-5]!=A[0])return 1;
  for(i,j=1;i+1<strlen(A)-5;i++,j++){
  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }

 printf("Circular password is not allowed.\n");
 return 0;
}
int main ()
{char a[SIZE_Z];
 char b[SIZE_Z];
 int hk_1,hk_2,hk_3,hk_4,hk_5,hk_6,hk_7,hk_8;
 while( gets(a)  ) {
  gets(b);
 if(a[0]=='E'&&a[1]=='N'&&a[2]=='D'&&b[0]=='E'&&b[1]=='N'&&b[2]=='D')break;
 hk_1=   unsame(a,b);    
 
 if(hk_1){hk_2=leth(a);   
 if(hk_2){hk_3=big(a);  
 if(hk_3){hk_4=small(a);   
 if(hk_4){hk_5=math(a);   
 if(hk_5){hk_6=mark(a);   
 if(hk_6){hk_7=symmetric(a);
 if(hk_7){hk_8=circular(a);
 if(hk_8)printf("Password is valid.\n");
       }
      }
     }
    }
   }
  }
 }
 }
 return 0;
}

#3415: Re:如何讀取空白字串


saitor362320 (Kira Yamato)


本題有個測資是"aB3caB3   "

最後一個字元是空白字元

char a[50]

while(scanf("%s",a)!=EOF)

會讀不到

請問一下該如何讀取?

 那就是一次讀整行的 gets()

 寫成 while( gets(a) != 0 )

原來如此~~感謝學姐微笑!

太久沒用差點忘了XDD


不過本題其實有兩個陣列a,b

本來是寫while(scanf("%s%s",a,b)!=EOF)

改成while(gets(a)!=0&&get(b)!=0)後

會出現RE

應該要怎麼寫才好呢?

 我是這樣寫沒錯阿@@

 附上宣告

 char password[101], check[101];

 while( gets(password) != 0 && gets(check) != 0 ) {

     ...

 }

還是不行耶

可能是因為我有用function

不過改掉function也是RE...

//===========

#include
#include
#define SIZE_Z 13
int unsame(const char A[SIZE_Z],const char B[SIZE_Z])
{int i;
if(strcmp(A,B)!=0){printf("Password settings are not consistent.\n");
 return 0;
}
 for(i=0;i  if(A[i]!=B[i]){printf("Password settings are not consistent.\n");
   return 0;
  }
 }
 return 1;
}
int leth(const char A[SIZE_Z])
{if(strlen(A)>=8&&strlen(A)<=12)
   return 1;
 else {
  printf("Password should contain 8 to 12 characters.\n");
  return 0;   
 }

}
int big(const char A[SIZE_Z])
{int i;
 for(i=0;i  if(A[i]>=65&&A[i]<=90){
   
   return 1;
  }
 }
 printf("Password should contain at least one upper-case alphabetical character.\n");
 return 0;
}
int small(const char A[SIZE_Z])
{int i;
 for(i=0;i  if(A[i]>=97&&A[i]<=122){
   
   return 1;
  }
 }
 printf("Password should contain at least one lower-case alphabetical character.\n");
 return 0;


}
int math(const char A[SIZE_Z])
{int i;
 for(i=0;i  if(A[i]>=48&&A[i]<=57){
   
   return 1;
  }
 }
 printf("Password should contain at least one number.\n");
 return 0;

}
int mark(const char A[SIZE_Z])
{int i;
 for(i=0;i  if(A[i]>=32&&A[i]<=33||
     A[i]>=35&&A[i]<=38||
     A[i]>=40&&A[i]<=47||
     A[i]>=58&&A[i]<=64||
     A[i]>=91&&A[i]<=96||
     A[i]>=123&&A[i]<=126||
     A[i]==41382||
     A[i]==41384
   ){
   
   return 1;
  }
 }
 printf("Password should contain at least one special character.\n");
 return 0;

}
int symmetric(const char A[SIZE_Z])
{int i;
 int j=strlen(A);
 int k;
 for(i=0,k=1;i  if(A[i]!=A[j-k])return 1;
 }
 printf("Symmetric password is not allowed.\n");
 return 0;
}
int circular(const char A[SIZE_Z])
{int i;
 int j=1;
 int hk=1;
 int string_long=strlen(A);
 int lenth=0;
 int remain_lenth;
 int sai;

 for(i=3;i<6;i++){
  if(A[i]==A[0]&&A[i+1]==A[1]){
  lenth=i;
  remain_lenth=strlen(A)-lenth;
  hk=0;
  break;
   }
 }
 


if(hk)return 1;
  
 sai=string_long%lenth;
  
 if(sai==0){
 for(i,j=1;i+1  
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==1){
  if(A[string_long-1]!=A[0])return 1;
  for(i,j=1;i+1  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==2){
 if(A[string_long-1]!=A[1]&&A[string_long-2]!=A[0])return 1;
  for(i,j=1;i+1  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==3){
  if(A[string_long-1]!=A[2]&&A[string_long-2]!=A[1]&&A[string_long-3]!=A[0])return 1;
  for(i,j=1;i+1  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==4){
  
  if(A[string_long-1]!=A[3]&&A[string_long-2]!=A[2]&&A[string_long-3]!=A[1]&&A[string_long-4]!=A[0])return 1;
  for(i,j=1;i+1  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }
 else if(sai==5){
  
 if(A[string_long-1]!=A[4]&&A[string_long-2]!=A[3]&&A[string_long-3]!=A[2]&&A[string_long-4]!=A[1]&&A[string_long-5]!=A[0])return 1;
  for(i,j=1;i+1  printf("(A[%d]==%c  ,A[%d]==%c\n",i+1,A[i+1],0+j,A[0+j]);
  if(A[i+1]!=A[0+j])return 1;
  }
 }

 printf("Circular password is not allowed.\n");
 return 0;
}
int main ()
{char a[SIZE_Z];
 char b[SIZE_Z];
 int hk_1,hk_2,hk_3,hk_4,hk_5,hk_6,hk_7,hk_8;
 while( gets(a)  ) {
  gets(b);
 if(a[0]=='E'&&a[1]=='N'&&a[2]=='D'&&b[0]=='E'&&b[1]=='N'&&b[2]=='D')break;
 hk_1=   unsame(a,b);    
 
 if(hk_1){hk_2=leth(a);   
 if(hk_2){hk_3=big(a);  
 if(hk_3){hk_4=small(a);   
 if(hk_4){hk_5=math(a);   
 if(hk_5){hk_6=mark(a);   
 if(hk_6){hk_7=symmetric(a);
 if(hk_7){hk_8=circular(a);
 if(hk_8)printf("Password is valid.\n");
       }
      }
     }
    }
   }
  }
 }
 }
 return 0;
}

 

ps:好像function不能用bool所以我用int...

#3419: Re:如何讀取空白字串


example (學姊)


 我是這樣寫沒錯阿@@

 附上宣告

 char password[101], check[101];

 while( gets(password) != 0 && gets(check) != 0 ) {

     ...

 }

還是不行耶

可能是因為我有用function

不過改掉function也是RE...

//===========

#include
#include
#define SIZE_Z 13


int main ()
{char a[SIZE_Z];
 char b[SIZE_Z];
 int hk_1,hk_2,hk_3,hk_4,hk_5,hk_6,hk_7,hk_8;
 while( gets(a)  ) {
  gets(b);
 if(a[0]=='E'&&a[1]=='N'&&a[2]=='D'&&b[0]=='E'&&b[1]=='N'&&b[2]=='D')break;
 hk_1=   unsame(a,b);    
 
 if(hk_1){hk_2=leth(a);   
 if(hk_2){hk_3=big(a);  
 if(hk_3){hk_4=small(a);   
 if(hk_4){hk_5=math(a);   
 if(hk_5){hk_6=mark(a);   
 if(hk_6){hk_7=symmetric(a);
 if(hk_7){hk_8=circular(a);
 if(hk_8)printf("Password is valid.\n");
       }
      }
     }
    }
   }
  }
 }
 }
 return 0;
}

 

ps:好像function不能用bool所以我用int...

 前面我附上宣告就是想說 RE 是不是因為超出陣列範圍

 題目說會小於 100 個字元

 那麼密碼只要超過 13 個字你就會得到 RE 了

 試試看吧

#3426: Re:如何讀取空白字串


saitor362320 (Kira Yamato)


 我是這樣寫沒錯阿@@

 附上宣告

 char password[101], check[101];

 while( gets(password) != 0 && gets(check) != 0 ) {

     ...

 }

還是不行耶

可能是因為我有用function

不過改掉function也是RE...

//===========

#include
#include
#define SIZE_Z 13


int main ()
{char a[SIZE_Z];
 char b[SIZE_Z];
 int hk_1,hk_2,hk_3,hk_4,hk_5,hk_6,hk_7,hk_8;
 while( gets(a)  ) {
  gets(b);
 if(a[0]=='E'&&a[1]=='N'&&a[2]=='D'&&b[0]=='E'&&b[1]=='N'&&b[2]=='D')break;
 hk_1=   unsame(a,b);    
 
 if(hk_1){hk_2=leth(a);   
 if(hk_2){hk_3=big(a);  
 if(hk_3){hk_4=small(a);   
 if(hk_4){hk_5=math(a);   
 if(hk_5){hk_6=mark(a);   
 if(hk_6){hk_7=symmetric(a);
 if(hk_7){hk_8=circular(a);
 if(hk_8)printf("Password is valid.\n");
       }
      }
     }
    }
   }
  }
 }
 }
 return 0;
}

 

ps:好像function不能用bool所以我用int...

 前面我附上宣告就是想說 RE 是不是因為超出陣列範圍

 題目說會小於 100 個字元

 那麼密碼只要超過 13 個字你就會得到 RE 了

 試試看吧

真的是這個原因@@""

非常感謝你^^"