fork download
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cctype>
  5.  
  6. typedef unsigned long long hash_t;
  7. const int PWD_LEN = 12;
  8.  
  9. char password[PWD_LEN+1];
  10.  
  11. template<typename T> T fast_pow(T x, T y)
  12. {
  13. if (y == 0)
  14. return 1;
  15. T half = fast_pow(x, y / 2);
  16. if (y % 2 == 0)
  17. return half*half;
  18. else
  19. return half*half*x;
  20. }
  21.  
  22. hash_t(*f_tab[])(hash_t) = {
  23. [](hash_t x)->hash_t { return x * 3; },
  24. [](hash_t x)->hash_t { return x * 4893147; },
  25. [](hash_t x)->hash_t { return _rotl64(x, 15); },
  26. [](hash_t x)->hash_t { return x + 32781696542221LLU; },
  27. [](hash_t x)->hash_t { return x ^ 0x83ff8af031d01deLLU; },
  28. [](hash_t x)->hash_t { return _byteswap_uint64(x); },
  29. [](hash_t x)->hash_t { return fast_pow(x | 1, 3ULL) ^ (x & 1); },
  30. [](hash_t x)->hash_t { return fast_pow(x | 1, 5ULL) ^ (x & 1); },
  31. [](hash_t x)->hash_t { return ~x; },
  32. [](hash_t x)->hash_t { return x - 123; },
  33. };
  34.  
  35. hash_t get_hash(const char* password, hash_t x)
  36. {
  37. while (*password)
  38. x = f_tab[*password++ - '0'](x);
  39. return x;
  40. }
  41.  
  42. void wrong()
  43. {
  44. puts("Wrong pin!");
  45. exit(0);
  46. }
  47.  
  48. void correct()
  49. {
  50. puts("Correct pin! gz!");
  51. exit(0);
  52. }
  53.  
  54. int main()
  55. {
  56. printf("Enter pin code ([0-9]{%d}): ", PWD_LEN);
  57. scanf_s("%s", password, PWD_LEN+1);
  58.  
  59. if (strlen(password) != PWD_LEN)
  60. wrong();
  61.  
  62. for (char *ptr = password; *ptr; ptr++)
  63. if (!isdigit(*ptr))
  64. wrong();
  65.  
  66. if (get_hash(password, 0x688e3d039d29a28eULL) == 0x8beda56841260d0d)
  67. correct();
  68. else
  69. wrong();
  70. }
Compilation error #stdin compilation error #stdout 0s 3340KB
stdin
Standard input is empty
compilation info
prog.cpp:23:16: error: type ‘__lambda0’ with no linkage used to declare function ‘hash_t __lambda0::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return x * 3; },
                ^
prog.cpp:23:39: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return x * 3; },
                                       ^
prog.cpp:24:16: error: type ‘__lambda1’ with no linkage used to declare function ‘hash_t __lambda1::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return x * 4893147; },
                ^
prog.cpp:24:45: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return x * 4893147; },
                                             ^
prog.cpp:25:16: error: type ‘__lambda2’ with no linkage used to declare function ‘hash_t __lambda2::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return _rotl64(x, 15); },
                ^
prog.cpp: In lambda function:
prog.cpp:25:45: error: ‘_rotl64’ was not declared in this scope
  [](hash_t x)->hash_t { return _rotl64(x, 15); },
                                             ^
prog.cpp: At global scope:
prog.cpp:25:48: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return _rotl64(x, 15); },
                                                ^
prog.cpp:26:16: error: type ‘__lambda3’ with no linkage used to declare function ‘hash_t __lambda3::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return x + 32781696542221LLU; },
                ^
prog.cpp:26:55: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return x + 32781696542221LLU; },
                                                       ^
prog.cpp:27:16: error: type ‘__lambda4’ with no linkage used to declare function ‘hash_t __lambda4::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return x ^ 0x83ff8af031d01deLLU; },
                ^
prog.cpp:27:58: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return x ^ 0x83ff8af031d01deLLU; },
                                                          ^
prog.cpp:28:16: error: type ‘__lambda5’ with no linkage used to declare function ‘hash_t __lambda5::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return _byteswap_uint64(x); },
                ^
prog.cpp: In lambda function:
prog.cpp:28:50: error: ‘_byteswap_uint64’ was not declared in this scope
  [](hash_t x)->hash_t { return _byteswap_uint64(x); },
                                                  ^
prog.cpp: At global scope:
prog.cpp:28:53: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return _byteswap_uint64(x); },
                                                     ^
prog.cpp:29:16: error: type ‘__lambda6’ with no linkage used to declare function ‘hash_t __lambda6::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return fast_pow(x | 1, 3ULL) ^ (x & 1); },
                ^
prog.cpp:29:65: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return fast_pow(x | 1, 3ULL) ^ (x & 1); },
                                                                 ^
prog.cpp:30:16: error: type ‘__lambda7’ with no linkage used to declare function ‘hash_t __lambda7::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return fast_pow(x | 1, 5ULL) ^ (x & 1); },
                ^
prog.cpp:30:65: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return fast_pow(x | 1, 5ULL) ^ (x & 1); },
                                                                 ^
prog.cpp:31:16: error: type ‘__lambda8’ with no linkage used to declare function ‘hash_t __lambda8::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return ~x; },
                ^
prog.cpp:31:36: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return ~x; },
                                    ^
prog.cpp:32:16: error: type ‘__lambda9’ with no linkage used to declare function ‘hash_t __lambda9::operator()(hash_t) const’ with linkage [-fpermissive]
  [](hash_t x)->hash_t { return x - 123; },
                ^
prog.cpp:32:41: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
  [](hash_t x)->hash_t { return x - 123; },
                                         ^
prog.cpp: In function ‘int main()’:
prog.cpp:57:35: error: ‘scanf_s’ was not declared in this scope
  scanf_s("%s", password, PWD_LEN+1);
                                   ^
prog.cpp: In lambda function:
prog.cpp:25:48: warning: control reaches end of non-void function [-Wreturn-type]
  [](hash_t x)->hash_t { return _rotl64(x, 15); },
                                                ^
prog.cpp: In lambda function:
prog.cpp:28:53: warning: control reaches end of non-void function [-Wreturn-type]
  [](hash_t x)->hash_t { return _byteswap_uint64(x); },
                                                     ^
stdout
Standard output is empty