Няшная / Говнокод #29073 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
/* Python:

def A004086(n):
return int(str(n)[::-1])
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int A004086(int n) {
    char str[12]; // Enough to hold the string representation of an int
    sprintf(str, "%d", n);
    int len = strlen(str);
    char reversed[12];
    
    for (int i = 0; i < len; i++) {
        reversed[i] = str[len - 1 - i];
    }
    reversed[len] = '\0'; // Null-terminate the string
    
    return atoi(reversed);
}

Результат переписывание с "Python" на "C". A004086 это последовательность из OEIS https://oeis.org/A004086

j123123 j123123, (Updated )

Комментарии (21, +21)

Няшная / Говнокод #29064 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
/* Windows doesn't support the fork() call; so we fake it by invoking
   another copy of Wget with the same arguments with which we were
   invoked.  The child copy of Wget should perform the same initialization
   sequence as the parent; so we should have two processes that are
   essentially identical.  We create a specially named section object that
   allows the child to distinguish itself from the parent and is used to
   exchange information between the two processes.  We use an event object
   for synchronization.  */
static void
fake_fork (void)
{
  char exe[MAX_PATH + 1];
  DWORD exe_len, le;
  SECURITY_ATTRIBUTES sa;
  HANDLE section, event, h[2];
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  struct fake_fork_info *info;
  char *name;
  BOOL rv;

  section = pi.hProcess = pi.hThread = NULL;

  /* Get the fully qualified name of our executable.  This is more reliable
     than using argv[0].  */
  exe_len = GetModuleFileName (GetModuleHandle (NULL), exe, sizeof (exe));
  if (!exe_len || (exe_len >= sizeof (exe)))
    return;

  sa.nLength = sizeof (sa);
  sa.lpSecurityDescriptor = NULL;
  sa.bInheritHandle = TRUE;

  /* Create an anonymous inheritable event object that starts out
     non-signaled.  */
  event = CreateEvent (&sa, FALSE, FALSE, NULL);
  if (!event)
    return;

  /* Create the child process detached form the current console and in a
     suspended state.  */
  xzero (si);
  si.cb = sizeof (si);
  rv = CreateProcess (exe, GetCommandLine (), NULL, NULL, TRUE,
                      CREATE_SUSPENDED | DETACHED_PROCESS,
                      NULL, NULL, &si, &pi);
  if (!rv)
    goto cleanup;

  /* Create a named section object with a name based on the process id of
     the child.  */
  name = make_section_name (pi.dwProcessId);
  section =
      CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
                         sizeof (struct fake_fork_info), name);
  le = GetLastError();
  xfree (name);
  /* Fail if the section object already exists (should not happen).  */
  if (!section || (le == ERROR_ALREADY_EXISTS))
    {
      rv = FALSE;
      goto cleanup;
    }

  /* Copy the event handle into the section object.  */
  info = MapViewOfFile (section, FILE_MAP_WRITE, 0, 0, 0);
  if (!info)
    {
      rv = FALSE;
      goto cleanup;
    }

  info->event = event;

  UnmapViewOfFile (info);

  /* Start the child process.  */
  rv = ResumeThread (pi.hThread);
  if (!rv)
    {
      TerminateProcess (pi.hProcess, (DWORD) -1);
      goto cleanup;
    }

  /* Wait for the child to signal to us that it has done its part.  If it
     terminates before signaling us it's an error.  */

  h[0] = event;
  h[1] = pi.hProcess;
  rv = WAIT_OBJECT_0 == WaitForMultipleObjects (2, h, FALSE, 5 * 60 * 1000);
  if (!rv)
    goto cleanup;

  info = MapViewOfFile (section, FILE_MAP_READ, 0, 0, 0);
  if (!info)
    {
      rv = FALSE;
      goto cleanup;
    }

Из исходников wget.

https://git.savannah.gnu.org/cgit/wget.git/tree/src/mswindows.c

rOBHOBO3Hblu_nemyx rOBHOBO3Hblu_nemyx, (Updated )

Комментарии (12, +12)

Няшная / Говнокод #29055 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
int IsEven(long long int number){
	if (number == 0) return 0; 
	long long int loc_num = 0;
	update: 
	
	if (number == loc_num+1) {return 1;
	} else if (number == (loc_num+1)*(-1)) { return 1;
	} else {
		if (number == loc_num+2) {return 0;
		} else if (number == (loc_num+2)*(-1)) { return 0;
		} else {
			if (number == loc_num+3) {return 1;
			} else if (number == (loc_num+3)*(-1)) { return 1;
			} else {
				if (number == loc_num+4) {return 0;
				} else if (number == (loc_num+4)*(-1)) { return 0;
				} else {
					if (number == loc_num+5) {return 1;
					} else if (number == (loc_num+5)*(-1)) { return 1;
					} else {
						if (number == loc_num+6) {return 0;
						} else if (number == (loc_num+6)*(-1)) { return 0;
						} else {
							if (number == loc_num+7) {return 1;
							} else if (number == (loc_num+7)*(-1)) { return 1;
							} else {
								if (number == loc_num+8) {return 0;
								} else if (number == (loc_num+8)*(-1)) { return 0;
								} else {
									if (number == loc_num+9) {return 1;
									} else if (number == (loc_num+9)*(-1)) { return 1;
									} else {
										if (number == loc_num+10) {return 0;
										} else if (number == (loc_num+10)*(-1)) { return 0;
										} else {
												loc_num+=10; 
												goto update;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

TurboLyudoed TurboLyudoed, (Updated )

Комментарии (3, +3)

Няшная / Говнокод #29001 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
// https://github.com/micropython/micropython/blob/1b89c503db690967d50699abe0bfa942f6f6b15e/ports/qemu/mcu/rv32/interrupts.c#L131

const char *lookup_cause(uint32_t mcause) {
    if (mcause & 0x80000000) {
        switch (mcause & 0x7FFFFFFF) {
            case 1:
                return exception_causes[1];
            case 3:
                return exception_causes[2];
            case 5:
                return exception_causes[3];
            case 7:
                return exception_causes[4];
            case 9:
                return exception_causes[5];
            case 11:
                return exception_causes[6];
            default:
                return (mcause >= 16) ?
                       exception_causes[7] :
                       exception_causes[0];
        }
    }

    switch (mcause) {
        case 0:
            return exception_causes[8];
        case 1:
            return exception_causes[9];
        case 2:
            return exception_causes[10];
        case 3:
            return exception_causes[11];
        case 4:
            return exception_causes[12];
        case 5:
            return exception_causes[13];
        case 6:
            return exception_causes[14];
        case 7:
            return exception_causes[15];
        case 8:
            return exception_causes[16];
        case 9:
            return exception_causes[17];
        case 11:
            return exception_causes[18];
        case 12:
            return exception_causes[19];
        case 13:
            return exception_causes[20];
        case 15:
            return exception_causes[21];
        default: {
            if ((mcause >= 24 && mcause <= 31) ||
                (mcause >= 48 && mcause <= 63)) {
                return exception_causes[22];
            }

            return exception_causes[0];
        }
    }
}

Микропитухон

j123123 j123123, (Updated )

Комментарии (4, +4)

Няшная / Говнокод #28998 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
int iseven(long long int number)
{
	struct Num {
		unsigned int x:1;
		unsigned int y:31;
		unsigned int z:32;
	} num = (*(struct Num*)(&number));
	return num.x; //Если результат 1, то нечётное.
}

Функция определения чётности числа посредством возврата младшего бита.

TurboLyudoed TurboLyudoed, (Updated )

Комментарии (6, +6)

Няшная / Говнокод #28995 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
longlong ** FUN_14000e5a0(longlong **param_1,LPCWSTR param_2,int param_3,uint param_4)

{
  uint uVar1;
  longlong **pplVar2;
  longlong **hFile;
  longlong *plVar3;
  longlong **pplVar4;
  DWORD DVar5;
  LONG local_38;
  undefined4 uStack_34;
  
  pplVar4 = (longlong **)0x0;
  uVar1 = param_4 & 0x1f;
  if ((param_4 & 0x1f) == 0) {
    uVar1 = 2;
  }
  pplVar2 = FUN_1400119f8(DAT_1400213a0,(longlong)param_1);
  if (pplVar2 == (longlong **)0x0) {
    return (longlong **)0x0;
  }
  if (param_3 == 1) {
    DVar5 = (DWORD)((param_4 >> 0x11 & 1) != 0);
    if ((param_4 >> 0x12 & 1) != 0) {
      DVar5 = 7;
    }
    hFile = (longlong **)
            CreateFileW(param_2,0x80000000,DVar5,(LPSECURITY_ATTRIBUTES)0x0,3,0x80,(HANDLE)0x0);
LAB_14000e70c:
    if (hFile == (longlong **)0xffffffffffffffff) goto LAB_14000e7ad;
  }
  else {
    if (param_3 == 2) {
      DVar5 = (DWORD)((param_4 >> 0x11 & 1) != 0);
      if ((param_4 >> 0x12 & 1) != 0) {
        DVar5 = 7;
      }
      hFile = (longlong **)
              CreateFileW(param_2,0xc0000000,DVar5,(LPSECURITY_ATTRIBUTES)0x0,4,0x80,(HANDLE)0x0);
      goto LAB_14000e70c;
    }
    if (param_3 != 3) {
      hFile = (longlong **)CONCAT44(uStack_34,local_38);
      goto LAB_14000e70c;
    }
    DVar5 = (DWORD)((param_4 >> 0x11 & 1) != 0);
    if ((param_4 >> 0x12 & 1) != 0) {
      DVar5 = 7;
    }
    hFile = (longlong **)
            CreateFileW(param_2,0xc0000000,DVar5,(LPSECURITY_ATTRIBUTES)0x0,2,0x80,(HANDLE)0x0);
    if (hFile == (longlong **)0xffffffffffffffff) {
      hFile = (longlong **)
              CreateFileW(param_2,0x40000000,DVar5,(LPSECURITY_ATTRIBUTES)0x0,5,0,(HANDLE)0x0);
      goto LAB_14000e70c;
    }
  }
  if (hFile != (longlong **)0x0) {
    if ((DAT_14001f140 == 0) || ((param_4 >> 0x13 & 1) != 0)) {
      pplVar2[1] = (longlong *)0x0;
    }
    else {
      plVar3 = (longlong *)HeapAlloc(DAT_1400204cc,0,(longlong)DAT_14001f140);
      pplVar2[1] = plVar3;
    }
    *pplVar2 = (longlong *)hFile;
    *(int *)(pplVar2 + 2) = DAT_14001f140;
    *(undefined4 *)((longlong)pplVar2 + 0x14) = 0;
    *(uint *)(pplVar2 + 4) = uVar1;
    *(uint *)((longlong)pplVar2 + 0x24) = (uint)(param_3 == 1);
    *(undefined4 *)((longlong)pplVar2 + 0x1c) = 1;
    if ((param_3 == 2) && ((param_4 >> 0x14 & 1) != 0)) {
      local_38 = 0;
      SetFilePointer(hFile,0,&local_38,2);
    }
    pplVar4 = hFile;
    if (param_1 == (longlong **)0xffffffffffffffff) {
      pplVar4 = pplVar2;
    }
    if (pplVar4 != (longlong **)0x0) {
      return pplVar4;
    }
  }
LAB_14000e7ad:
  if (param_1 == (longlong **)0xffffffffffffffff) {
    param_1 = pplVar2;
  }
  FUN_14001192c(DAT_1400213a0,(longlong)param_1);
  return pplVar4;
}

BelCodeMonkey BelCodeMonkey, (Updated )

Комментарии (5, +5)