fork(1) download
  1. // https://p...content-available-to-author-only...j.com/problems/FR_07_03/
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <cstdio>
  7. #include <cctype>
  8. #include <cstring>
  9. #include <map>
  10. #include <stack>
  11. #include <iterator>
  12.  
  13.  
  14. using namespace std;
  15.  
  16. typedef vector<unsigned int> VI;
  17. typedef long long LL;
  18. #define FOR(c, from, to) for(int c = from; c <= (to); ++c)
  19. #define FORD(c, from, to) for(int c = from; c >= (to); – –x)
  20. #define REP(c, n) for(int c = 0; c < (n); ++c)
  21. #define VAR(v, n) typeof(n) v = (n)
  22. #define ALL(c) (c).begin(), (c).end()
  23. #define SIZE(c) ((int)(c).size())
  24. #define PB push_back
  25. #define ST first
  26. #define ND second
  27.  
  28. static char AsciiSpecialCharacters[32] = {'!', '"', '#', '$', '%', '&', '*', '\'' ,'(', ')','+' , ',', '-', '.', '/', ':' ,';', '<', '=', '>', '?', '@' , '[', '\\', ']', '^', '_', '`', '{', '}', '|', '~'};
  29.  
  30. void print_msg(string function, string msg);
  31. bool is_login_and_password_are_correct(string &, string &);
  32. bool is_lenght_correct(string &, string &);
  33. bool is_login_contain_illegal_char(string & login);
  34. bool is_password_meet_criteria(string &);
  35. void print_result(vector<string> & arr);
  36. void print_accounts(map<string, string> & account);
  37. bool is_account_exist(map<string,string> & account, string &);
  38. string change_to_lower_case(string &);
  39. void create_account(map<string, string> & account, string & login, string & password);
  40. bool is_password_correct(map<string,string> & accounts, string & login, string & password);
  41. // void remove_space(string & loginAndPassword, string * login, string * password);
  42.  
  43. int main(){
  44.  
  45. int attemps;
  46. map<string, string> account;
  47. string loginAndPassword;
  48.  
  49. string login;
  50. string password;
  51. vector<string> result;
  52. string command;
  53.  
  54.  
  55. while(cin >> command >> attemps){
  56. if(command == "register"){
  57. for(int i=0; i<attemps; i++){
  58. cin >> login >> password;
  59. if(is_login_and_password_are_correct(login, password)){
  60. if(!is_account_exist(account, login)){
  61. create_account(account, login, password);
  62. result.PB("Zarejestrowano");
  63. }else
  64. {
  65. result.PB("Login zajety");
  66. }
  67. }else{
  68.  
  69. result.PB("Blad");
  70. }
  71. }
  72. }
  73. else if(command == "login"){
  74. for(int i=0; i<attemps; i++){
  75. cin >> login >> password;
  76. if(is_account_exist(account, login)){
  77. if(is_password_correct(account, login, password)){
  78. result.PB("Zalogowano");
  79. }else
  80. {
  81. result.PB("Zle haslo");
  82. }
  83. }else
  84. {
  85. result.PB("Konto nie istnieje");
  86. }
  87. }
  88. }
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95. print_result(result);
  96.  
  97.  
  98.  
  99. return 0;
  100. }
  101. void print_msg(string function, string msg){
  102. cout << function << " " << msg << "\n";
  103. }
  104.  
  105. void print_result(vector<string> & arr){
  106. FOR(i, 0, SIZE(arr)-1){
  107. cout << arr[i] << "\n";
  108. }
  109. }
  110. void print_accounts(map<string, string> & account){
  111. cout << "\n";
  112. for(auto it : account){
  113. cout << it.first << " " << it.second << "\n";
  114. }
  115. }
  116. bool is_lenght_correct(string & login, string & password){
  117.  
  118. if(login.length()<3 || login.length()>12){
  119. return false;
  120. }
  121. if(password.length()<5 || password.length()>15){
  122. return false;
  123. }
  124.  
  125.  
  126. return true;
  127. }
  128. bool is_login_contain_illegal_char(string & login){
  129.  
  130. char character;
  131. FOR(i, 0, login.length()-1){
  132. character = login[i];
  133.  
  134. FOR(j, 0, 32){
  135. if(character == AsciiSpecialCharacters[j]){
  136. cout << "IS_LOGIN_CONTAIN_ILLEGAL_CHAR: yes its " << character << endl;
  137. return false;
  138. }
  139. }
  140. }
  141. return true;
  142. }
  143. /* these criteria is:
  144. - number
  145. - special character
  146. - character in upper case
  147. - character in lower case
  148. */
  149. bool is_password_meet_criteria(string & password){
  150. bool numberOccurence = false;
  151. bool specialCharacterOccurence = false;
  152. bool upperCaseCharacterOccurence = false;
  153. bool lowerCaseCharacterOccurence = false;
  154.  
  155. FOR(i, 0, password.length()){
  156. if(numberOccurence == false) FOR(n, 48, 57){
  157. if((char)(n) == password[i]){
  158. numberOccurence = true;
  159. }
  160. }
  161. if(specialCharacterOccurence == false) FOR(j, 0, 32){
  162. if(AsciiSpecialCharacters[j] == password[i]){
  163. specialCharacterOccurence = true;
  164. }
  165. }
  166. if(upperCaseCharacterOccurence == false) FOR(c, 65, 90){
  167. if((char)(c) == password[i]){
  168. upperCaseCharacterOccurence = true;
  169. }
  170. }
  171. if(lowerCaseCharacterOccurence == false) FOR(c, 97, 122){
  172. if((char)(c) == password[i]){
  173. lowerCaseCharacterOccurence = true;
  174. }
  175. }
  176. }
  177. if(!(numberOccurence && specialCharacterOccurence && upperCaseCharacterOccurence && lowerCaseCharacterOccurence)){
  178. return false;
  179. }
  180. return true;
  181. }
  182. bool is_login_and_password_are_correct(string & login, string & password){
  183. if(!is_lenght_correct(login, password)){
  184. print_msg("IS_LENGHT_CORRECT: ", "too short or too long");
  185. return false;
  186. }
  187. if(!is_login_contain_illegal_char(login)){
  188. return false;
  189. }
  190. if(!is_password_meet_criteria(password)){
  191. print_msg("IS_PASSWORD_MEET_CRITERIA:", "no");
  192. return false;
  193. }
  194. return true;
  195. }
  196. string change_to_lower_case(string & text){
  197.  
  198. string lower_text = text;
  199.  
  200. FOR(i, 0, text.length()){
  201. lower_text[i] = tolower(lower_text[i]);
  202. }
  203. return lower_text;
  204. }
  205. void create_account(map<string, string> & account, string & login, string & password){
  206.  
  207. string lowerCaseLogin = change_to_lower_case(login); // changing login to lower case because it doenst make an odds
  208. account[lowerCaseLogin] = password;
  209.  
  210. }
  211. bool is_account_exist(map<string,string> & accounts, string & login){
  212. string lowerCaseLogin = change_to_lower_case(login);
  213. for(auto it : accounts){
  214. if((it.first.compare(lowerCaseLogin))==0){
  215.  
  216. return true;
  217. }
  218. }
  219. return false;
  220. }
  221.  
  222. bool is_password_correct(map<string,string> & accounts, string & login, string & password){
  223. string lowerCaseLogin = change_to_lower_case(login);
  224. for(auto it : accounts){
  225. if((it.first.compare(lowerCaseLogin))==0){
  226. if((it.second.compare(password))==0){
  227. return true;
  228. }
  229. }
  230. }
  231. return false;
  232. }
  233. // void remove_space(string & loginAndPassword, string * login, string * password){
  234. // string word = "";
  235. // int startPosition = 0;
  236. // for (auto c : loginAndPassword) {
  237. // cout << "REMOVE_SPACE: " << c << endl;
  238. // if (c == ' ') {
  239. // * login = word;
  240. // word = "";
  241. // break;
  242. // }
  243. // else{
  244. // word = word + c;
  245. // }
  246. // startPosition++;
  247. // }
  248. // word = "";
  249. // for(int i=startPosition; i<loginAndPassword.length(); i++){
  250.  
  251. // word = word + loginAndPassword[i]; // probably there is problem
  252. // }
  253. // * password = word;
  254. // }
  255.  
  256.  
  257.  
  258.  
Success #stdin #stdout 0s 4352KB
stdin
register 3
bajtek13 Haslo123@
BITEK 123456789
!bajtek13 bajteK55%
login 5
bajtek13 bajteK55%
bajtek13 Haslo123@
BITEK 123456789
bajtocjusz haselko49
bitariusz 123haSlo!@#
register 1
BITEK Dobrehaslo1!
login 1
BITEK Dobrehaslo1!
stdout
IS_LOGIN_CONTAIN_ILLEGAL_CHAR: yes its b
IS_LOGIN_CONTAIN_ILLEGAL_CHAR: yes its B
IS_LOGIN_CONTAIN_ILLEGAL_CHAR: yes its !
IS_LOGIN_CONTAIN_ILLEGAL_CHAR: yes its B
Blad
Blad
Blad
Konto nie istnieje
Konto nie istnieje
Konto nie istnieje
Konto nie istnieje
Konto nie istnieje
Blad
Konto nie istnieje