Problem ID :h006. F.密碼安全設定

New Thread

User 請告訴我輸入,或是錯誤的地方

falcon SendIMessage
0w1

h006. F.密碼安全設定 | From: 182.234.208.154 | Post Date:2014-05-20 20:24:22.0

*** 第 2 點 (80%):WA
與正確輸出不相符(line:10)
您的答案為: Password should contain ...略
正確答案為: Password is valid.
 
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
  string a, b;
  string sp = "~!@#$%^&*()_+|`-=\{}[]:”;’<>?,./ ";
  string tmp;
  bool upCase, lowCase, hasNum, hasSp, isSym, isCir;
  while (cin >> a >> b)
    {
      if (a == "END" && b == "END") break; 
      upCase = lowCase = hasNum = hasSp = isCir = false;
      isSym = true;
      if (a != b) 
{
 cout << "Password settings are not consistent." << endl;
 continue;
}
      else if (a.length() > 12 || a.length() < 8)
{
 cout << "Password should contain 8 to 12 characters." << endl;
 continue;
}
      for (int i = 0; i < a.length(); i++)
{
 if (a[i] >= 'A' && a[i] <= 'Z')
   upCase = true;
 else if (a[i] >= 'a' && a[i] <= 'z')
   lowCase = true;
 else if (a[i] >= '0' && a[i] <= '9')
   hasNum = true;
 if (upCase == true && lowCase == true && hasNum == true) break;
}
      if (upCase == false)
{
 cout << "Password should contain at least one upper-case alphabetical character." << endl;
 continue;
}
      else if (lowCase == false)
{
 cout << "Password should contain at least one lower-case alphabetical character." << endl;
 continue;
}
      else if (hasNum == false)
{
 cout << "Password should contain at least one number." << endl;
 continue;
}
      for (int i = 0; i < a.length(); i++)
{
 for (int k = 0; k < 33; k++)
   if (a[i] == sp[k])
     {
hasSp = true;
break;
     }
 if (hasSp == true) 
   break;
}
      if (hasSp == false) 
{
 cout << "Password should contain at least one special character." << endl;
 continue;
}
      for (int i = 0, k = a.length() - 1; i < a.length(); i++, k--)
{
 if (a[i] != a[k])
   {
     isSym = false;
     break;
   }
}
      if (isSym == true)
{
 cout << "Symmetric password is not allowed." << endl;
 continue;
}
      for (int i = 0; i < a.length()-3; i++)
{
 sp = "";
 sp += a[i]; sp += a[i+1]; sp += a[i+2];
 for (int k = i+1; k < a.length(); k++)
   {
     tmp = "";
     tmp += a[k]; tmp += a[k+1]; tmp += a[k+2];
     if (sp == tmp)
{
 isCir = true;
 break;
}
   }
 if (isCir == true)
   break;
}
      if (isCir == true)
{
 cout << "Circular password is not allowed." << endl;
 continue;
}
      cout << "Password is valid." << endl;
    }
  return 0;
}
 
 


文章類型: 一般 | Reply | Back
User Re:請告訴我輸入,或是錯誤的地方

sagit SendIMessage
sagit

h006. F.密碼安全設定 | From: 175.180.204.115 | Post Date:2014-05-21 23:04:38.0

 string sp = "~!@#$%^&*()_+|`-=\\{}[]:”;’<>?,./ ";

也可能還有我沒注意到的地方。 

 


文章類型: 一般 | Reply | Back
User Re:請告訴我輸入,或是錯誤的地方

falcon SendIMessage
0w1

h006. F.密碼安全設定 | From: 182.234.208.154 | Post Date:2014-06-02 17:03:31.0

還是請您告訴我輸入,我將那個部分換過,還是沒有改變,自己手算一次可能會找到原因,謝謝。

 


文章類型: 一般 | Reply | Back
User Re:請告訴我輸入,或是錯誤的地方

sagit SendIMessage
sagit

h006. F.密碼安全設定 | From: 112.105.115.244 | Post Date:2014-06-03 22:38:13.0

只要是NPSC的題目, 絕大部分都是用官方測資,
因為測資檔很大, 而且可能會有很多組,
所以麻煩你以後自己去官網找,
這題的題目在:
http://contest.cc.ntu.edu.tw/npsc2005/
初賽裡的「下載裁判測試資料」那個地方。
 


文章類型: 一般 | Reply | Back

New Thread

ZeroJudge Forum