inlineboolSubStringDetermine(string s) { unordered_map<string, int> hash; // i : length of sub string //for (int len = 3; len < s.size() - 1; len++) int len = 3; { for (int i = 0; i < s.size() - len + 1; i++) { string sub = s.substr(i, len); hash[sub] = hash[sub] + 1; if (hash[sub] > 1) returnfalse; } } returntrue; }
inlineintlowbit(int x) { return x & (-x); }
inlineboolTypeDetermine(string s) { int cnt = 0; for (auto c : s) { if (isupper(c)) cnt |= 1; elseif (islower(c)) cnt |= (1 << 1); elseif (isdigit(c)) cnt |= (1 << 2); else cnt |= (1 << 3); } // count 1 int type = 0; for (; cnt; cnt -= (lowbit(cnt))) type++; return type >= 3; }
publicclassMain{ privatestaticbooleansubstringDetermine(String s){ int n = s.length(); int len = 3; Set<String> set = new HashSet<>(); for (int i = 0; i <= n - len; i++) { String sub = s.substring(i, i + len); if (set.contains(sub)) returnfalse; set.add(sub); } returntrue; } privatestaticintlowbit(int x){ return x & -x; } privatestaticbooleantypeDetermine(String s){ int cnt = 0; for (int i = 0, n = s.length(); i < n; i++) { char c = s.charAt(i); if (Character.isUpperCase(c)) cnt |= 1; elseif (Character.isLowerCase(c)) cnt |= 1 << 1; elseif (Character.isDigit(c)) cnt |= 1 << 2; else cnt |= 1 << 3; } int type = 0; for (; cnt != 0; cnt -= lowbit(cnt)) ++type; return type >= 3; } publicstaticvoidmain(String[] args){ Scanner in = new Scanner(System.in); String s; for (; in.hasNext();) { s = in.nextLine(); if (s.length() <= 8 || !typeDetermine(s) || !substringDetermine(s)) { System.out.println("NG"); } else { System.out.println("OK"); } } } }