Guest User

Untitled

a guest
May 25th, 2015
270
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int make1(int number) {
  7. if (number == 0) return 4;
  8. int b[10], length = 0;
  9. while (number > 0) {
  10. int digit = number % 2;
  11. if (digit == 0) digit = 4;
  12. if (digit == 1) digit = 7;
  13. b[length++] = digit;
  14. number /= 2;
  15. }
  16. int result = 0;
  17. for (int i = 0, j = 1; i < length; i++, j *= 10) {
  18. result += b[i] * j;
  19. }
  20. return result;
  21. }
  22.  
  23. int make2(int number) {
  24. int b[10], length = 0;
  25. while (number > 0) {
  26. int digit = number % 2;
  27. if (digit == 0) digit = 7;
  28. if (digit == 1) digit = 4;
  29. b[length++] = digit;
  30. number /= 2;
  31. }
  32. int result = 0;
  33. for (int i = 0, j = 1; i < length; i++, j *= 10) {
  34. result += b[i] * j;
  35. }
  36. return result;
  37. }
  38.  
  39. int main() {
  40. int n, a[1234];
  41. for (int i = 0; i < 512; i++) {
  42. a[i] = make1(i);
  43. }
  44. for (int i = 1; i < 1024; i++) {
  45. a[i + 511] = make2(i + 1);
  46. }
  47. sort(a, a + 1024);
  48. scanf("%d", &n);
  49. for (int i = 0; i < 1024; i++) {
  50. if (a[i] == n) {
  51. printf("%d", i + 1);
  52. break;
  53. }
  54. }
  55. return 0;
  56. }
RAW Paste Data