1. Си / Говнокод #8475

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    for ( i = 0; i <= n; i++ )
    {
    
        k = 0;
    
        for ( j = ( 2 * n - i - 1 ); k == 0; k++ )
        {
            a1 = a1 & ~ ( 1 << ( j ) );
            a1 = a1 | ( ( ( a1 >> ( i ) ) & 1 ) << ( j ) );
        };
    }

    по условию задачи (реверсирование битов числа) студентам нельзя было юзать if.

    bieber, 10 Ноября 2011

    Комментарии (18)
  2. Си / Говнокод #8455

    +127

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    #include <stdio.h>
    #include <iostream>
    #include <cmath>
    #include <iostream>
    #include <stdio.h>
    #include <math.h>
    #include <limits.h>
    #include <values.h>
    #include <conio.h>
    #include <iostream.h>
    #include <stdlib.h>
    #include <cstdlib>
    #include <stdlib.h>
    #include <VCL.h>
    #include <iostream.h>
    #include <string.h>
    #include <dos.h>
     
    FILE *f=fopen( "C:\\input.txt" , "r");
    FILE *f2=fopen( "C:\\output.txt" , "w");
     
     
    int main() {
     void readmas(float x[10][10],char name,int n);
     void readmas2(float x[10],char name,int n);
     float A[10][10];
     float B[10];
     float x[10][100];
     int i,j, ha,hb,wa,n;
     float E;
     int k = 1;
     int m = 1;
     float s;
     
     
     printf("Vvedite kolichestvo uravnenij:\n");
     scanf("%d",&n);
     printf("\nA:\n");
     readmas(A, 'A',n);
     printf("\nB:\n");
     readmas2(B, 'B',n);
     printf("\nVvedite tochnost resheniya:\n");
     scanf("%f",&E);
     printf("\n");
     
    while (m > E) {
         m = 0;
         for (i = 1; i <= n; i++) {
            s = 0;
            for (j = 1; j <= n; j++) {
                if (i != j) {
                    s = s + A[i][j]*x[j][k];
                }
            }
            x[i][k+1] = (B[i]-s)/A[i][i];
            if (abs(x[i][k+1] - x[i][k]) > m) {
                m = abs(x[i][k+1] - x[i][k]);
            }
         }
         k = k + 1;
     }
     
     for (i = 1; i <= n; i++) {
            cout<<x[i][k];
            cout<<"\n";
     }
     
     getch();
     return 0;
    }
     
     
    void readmas(float x[10][10],char name,int n)
    {
     
    int i,j;
    for (i=1; i<=n;i++) {
        for (j=1; j<=n; j++) {
            fscanf(f, "%d", &x[i][j]);
            printf("%d ", x[i][j])     ;
            }
            printf("\n");
    }

    timka, 08 Ноября 2011

    Комментарии (75)
  3. Си / Говнокод #8397

    +110

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    switch (x)
    if (z == 5)
    {
        case 10:
            y = 1;
    }
    else
    {
        case 11:
            if (z > 10)
                y = 2;
            else
            {
                default:
                    y = 3;
            }
    }

    Недавно показали вот такой вот switch.
    Первое, что пришло в голову: "wtf?! это ведь даже не скомпилится".
    Я оказался не прав.

    govnopetya, 02 Ноября 2011

    Комментарии (72)
  4. Си / Говнокод #8381

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    #include <stdio.h>
    #include <stdlib.h>
    
    #define $ /* */
    
    #define ARGV argv
    
    #define if($x) int main(int argc, char *argv[])
    
    #define $start 1  
    
    #if PERL
     sub atoi { $_[0] }
     $ argc=@ARGV;
     $ start=0;
     $ x=1;
    #endif
    
    if($x)
    {
     int $ sum;
     int $ i;
     
     $ sum=0;
    
     for ( $ i = $start; $ i < $ argc ; $ i++) {
       $ sum += atoi ($ ARGV [$ i]);}
    
     printf("%d\n", $ sum);
    
    exit(0);
    }

    Пришла в голову вот такая вот идея, уже пишу серьезный проект, а вам даю на оценку вот такой вот код.
    Думаю вообще связать это все дело еще и с PHP, вот таким вот образом:
    <?php system('./home/Cuberpunk/private/iGuruCodder/SeriousProject/main 15 12 15'); ?>
    Хотел запостить на Хабр, но нету там аккаунта, поэтому пишу сюда ;)
    Оценивайте, комментируйте. Сейчас работаю над крупным проектом на эту тему, ждите.
    Если кому интересно, то вот моя темка на форуме, где все более подробно описано:
    http://forum.antichat.ru/threadedpost2883414.html

    Cyber-punk, 01 Ноября 2011

    Комментарии (28)
  5. Си / Говнокод #8371

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    /* ... */
    /**************************************************************************************
      cpu_information () parse /proc/cpuinfo to get information about CPU 
     **************************************************************************************/
    int cpu_information (data* user_data, int pos)
    {
      FILE *cpufp/* /proc/cpuinfo */ /*, *sysfs_max_cpu_freq_fp  /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq */;
       
      char* ch = (char*)malloc (MAXLEN);
      char* line = (char*)malloc (MAXLEN);
      char* buf = (char*)malloc (MAXLEN);
      
      GtkTreeIter iter[2];
      // int y = 0;
      if ((cpufp = fopen(CPU_INFORMATION_FILE, "r")) == NULL)
        printf ("%s\n", "Error opening /proc/cpuinfo");
    
      while (fgets (ch, MAXLEN, cpufp) != NULL) 
      {
        if (!strncmp (ch, "processor", 9)) 
        {
          sscanf (ch, "%*s %*s %s", line);
          strcpy (buf, "CPU");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[0],NULL, pos, 0, buf, 1, line, -1);
        } else if (!strncmp(ch, "vendor_id", 9))
        {
          sscanf(ch,"%*s %*s %s", line);
          strcpy (buf, "Processor type:");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1); 
        } else if (!strncmp(ch, "model name", 10))
        {
          strcpy(buf, "Model name");
          ch[strlen(ch)-1] = '\0'; //delete '\n' symbol from the end of string
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, &ch[13], -1);
        } else if (!strncmp(ch, "cpu MHz", 7))
        {
          int curr_cpu_freq;
          sscanf(ch, "%*s %*s %*s %d\n", &curr_cpu_freq);
          sprintf(line, "%d", curr_cpu_freq);
          strcpy (buf, "Current Processor Speed in MHz");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line,-1);
          /*
    	 Begin parsing /sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq 
    	 
          sprintf (sysfs_max_cpu_freq_path, SYSFS_CPU_MAX_FREQ_FORMAT_STRING, y);
          if ((sysfs_max_cpu_freq_fp = fopen (sysfs_max_cpu_freq_path, "r")) == NULL) {
        	  printf("%s %s\n", "Error opening",  sysfs_max_cpu_freq_path);
          }
          while (fgets (line, MAXLEN, sysfs_max_cpu_freq_fp) != NULL)
          {
    	sscanf (line, "%d", &max_cpu_freq);
    	sprintf (line, "%d", max_cpu_freq/1000);
    	strcpy (buf, "Max Processor Speed in MHz");
    	gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[2],&iter[1], pos, 0, buf, 1, line,-1);
          }
          y++;
          
    	 End parsing 
           
          fclose (sysfs_max_cpu_freq_fp);*/
        }  else if (!strncmp(ch, "cache size", 10))
        {
          sscanf(ch, "%*s %*s %*s %s", line);
          strcpy (buf, "Processor cache size");
          strcat (line, " KB");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
    
        } else if (!strncmp(ch, "bogomips", 8)) 
        {
          sscanf(ch, "%*s %*s %s", line);
          strcpy (buf, "Processor speed in Bogomips");
          gtk_tree_store_insert_with_values (user_data->InformationTreeStore, &iter[1],&iter[0], pos, 0, buf, 1, line, -1);
          cpu_temperature (user_data,&iter[0], pos); //get CPU temperature.
        }
        pos++;
      }
    
      free (buf);
      free (line);
      free (ch);
      //free (sysfs_max_cpu_freq_path);
      fclose (cpufp);
      return 0;
    }
    /* ... */

    По просьбам трудящихся http://govnokod.ru/7979#comment116436

    По коду:
    1) хорошо бы проверять, что попытался выделить;
    2) ошибка произошла успешно — начинаем парсить...;
    3) для решения таких задач стоит обратить своё внимание на, например, PyGTK.

    P.S. Если уж совсем не в мочь и к строкам так тянет,
    то допилите под себя LiteC, у Г.Шилдта есть что подсмотреть.

    sayidandrtfm, 31 Октября 2011

    Комментарии (20)
  6. Си / Говнокод #8358

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    #define DelayUs(x) \
                        #if x >= 5 \
                            { \
                            delayus_variable=(unsigned char)(x/DelayDivisor); \
                            asm("movlb (_delayus_variable) >> 8"); \
                            WaitFor1Us; } \
                            asm("decfsz (_delayus_variable)&0ffh,f"); \
                            Jumpback \
                        #elif x == 4 \
                            Delay1us; Delay1us; Delay1us; Delay1us \
                        #elif x == 3 \
                            Delay1us; Delay1us; Delay1us \
                        #elif x == 2 \
                            Delay1us; Delay1us \
                        #elif x == 1 \
                            Delay1us \
                        #else \
                        #endif

    Стажер

    alexoy, 30 Октября 2011

    Комментарии (14)
  7. Си / Говнокод #8346

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    int LoadFunctions() {
        HINSTANCE kernel;
        decrypt(krn);
        if((kernel = LoadLibraryA(decb)) == NULL) {
            return 1;
        } else {
            decrypt(crf);
            if((CreateFile = (CreateFileP) GetProcAddress(kernel, decb)) == NULL) return 1;
            decrypt(sfpe);
            if((SetFilePointerEx = (SetFilePointerExP) GetProcAddress(kernel, decb)) == NULL) return 1;
            decrypt(wf);
            if((WriteFile = (WriteFileP) GetProcAddress(kernel, decb)) == NULL) return 1;
            decrypt(ch);
            if((CloseHandle = (CloseHandleP) GetProcAddress(kernel, decb)) == NULL) return 1;
            decrypt(ffb);
            if((FlushFileBuffers = (FlushFileBuffersP) GetProcAddress(kernel, decb)) == NULL) return 1;
        }
        HANDLE user;
        decrypt(us);
        if((user = LoadLibraryA(decb)) == NULL) {
            return 1;
        } else {
            decrypt(mba);
            if((MessageBoxA = (MessageBoxAP) GetProcAddress(user, decb)) == NULL) {
                return 1; // ну зачем?
            }
        }
    
        return 0;
    }

    Бида-бида, MessageBox не загрузилась - повод завершить выполнение. Хотя все важнейшие функции уже на месте.

    danilissimus, 28 Октября 2011

    Комментарии (8)
  8. Си / Говнокод #8328

    +138

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    POINT Point_X(POINT a1,POINT a2,POINT a3,POINT a4){
    	POINT T;
    	if(((a1.x<=T.x)&&(a2.x>=T.x)&&(a3.x<=T.x)&&(a4.x >=T.x))||((a1.y<=T.y)&&(a2.y>=T.y)&&(a3.y<=T.y)&&(a4.y>=T.y))){
    		float x1=a1.x,x2=a2.x,x3=a3.x,x4=a4.x,y1=a1.y,y2=a2.y,y3=a3.y,y4=a4.y;
    		float k1,k2;
    		if(y2-y1!=0){
    			k1=(x2-x1)/(y2-y1);
    			if(y4-y3!=0){
    				k2=(x4-x3)/(y4-y3);
    				if(k1!=k2){
    					T.x=((a1.x*a2.y-a2.x*a1.y)*(a4.x-a3.x)-(a3.x*a4.y-a4.x*a3.y)*(a2.x-a1.x))/((a1.y-a2.y)*(a4.x-a3.x)-(a3.y-a4.y)*(a2.x-a1.x));
    					T.y=((a3.y-a4.y)*T.x-(a3.x*a4.y-a4.x*a3.y))/(a4.x-a3.x);
    					T.x*=-1;
    					return T;
    				}else{
    					T.x=969; T.y=969;
    					//text2("Паралельны");
    				}
    			}else{
    				T.x=969; T.y=969;
    				//text2("Паралельны");
    			}
    		}else{
    			T.x=969; T.y=969;
    			//text2("Паралельны");
    		}
    	}else{
    		//text2("Пересечение вне отрезка");
    		T.x=979; T.y=979;
    		return T;
    	}
    
    }

    http://programmersforum.ru/showpost.php?s=2ce0c55a82de1e293561c547e 291e374&p=858737&postcount=5

    Akari, 27 Октября 2011

    Комментарии (9)
  9. Си / Говнокод #8299

    +131

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    #include <stdio.h>
    #include <conio.h>
    #include <locale>
    #include <math.h>
    int main(void)
    {
    	setlocale (LC_ALL, "Russian");
    	char c;
    	printf ("Пожалуйста\, введите символ ");
    	scanf ("%c", &c);
    	
    	switch (c)
    	{
    	case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': printf ("Это цифра"); break;
    	default: printf ("Вы ввели не цифру\!\!\!");
    	}
    	getch ();
    	float x, y1, y2;
    	printf ("\n\n Пожалуйста введите значение \"X\" ");
    	scanf ("%f", &x);
    
    	if ((x<=5)&&(x>3))
    	{
    		y1=log(2*x)+3*x;
    		y2=sqrt(x)+0.75*x;
    		printf ("\n\n При \"X\" = %g\, z(x) имеет два значения: %f и %f", x, y1, y2);
    	}
    	else
    	{
    		{
    		if (x>3)
    		{
    			y1=sqrt(x)+0.75*x;
    			printf ("\n\n При \"X\" = %g\, z(x) = %f", x, y1);
    		}
    		if ((x<=5)&&(x>0))
    		{
    			y1=log(2*x)+3*x;
    			printf ("\n\n При \"X\" = %g\, z(x) = %f", x, y1);
    		}
    		}
    		if (x<=0)
    
    		printf ("\n\n Внимание, введенное значение \"x\" не удолетворяет ОДЗ");
    	}
    		getch ();
    		int pzdc;
    		printf ("\n\n Пожалуйста введите порядковый номер месяца ");
    		scanf ("%d", &pzdc);
    		
    		switch (pzdc)
    		{
    		case 1:
    			printf ("\n 31");
    			break;
    		case 2:
    			printf ("\n 28");
    			break;
    		case 3:
    			printf ("\n 31");
    			break;
    		case 4:
    			printf ("\n 30");
    			break;
    		case 5:
    			printf ("\n 31");
    			break;
    		case 6:
    			printf ("\n 30");
    			break;
    		case 7:
    			printf ("\n 31");
    			break;
    		case 8:
    			printf ("\n 31");
    			break;
    		case 9:
    			printf ("\n 30");
    			break;
    		case 10:
    			printf ("\n 31");
    			break;
    		case 11:
    			printf ("\n 30");
    			break;
    		case 12:
    			printf ("\n 31");
    			break;
    		default:
    			printf ("ОШИБКА!!!"); break;
    		}
    getch ();
    return (0);
    }

    лаба. знаю что тут не любят, но все же

    KirAmp, 26 Октября 2011

    Комментарии (22)
  10. Си / Говнокод #8298

    +140

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    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
    void Lcd_goto(uc8 x, uc8 y)
    {
            int str;
            if (x == 0)
            {
                    switch (y)
                    {
                    case 0:  str = 0x80; break;
                    case 1:  str = 0x81; break;
                    case 2:  str = 0x82; break;
                    case 3:  str = 0x83; break;
                    case 4:  str = 0x84; break;
                    case 5:  str = 0x85; break;
                    case 6:  str = 0x86; break;
                    case 7:  str = 0x87; break;
                    case 8:  str = 0x88; break;
                    case 9:  str = 0x89; break;
                    case 10: str = 0x8A; break;
                    case 11: str = 0x8B; break;
                    case 12: str = 0x8C; break;
                    case 13: str = 0x8D; break;
                    case 14: str = 0x8E; break;
                    case 15: str = 0x8F; break;
                    }
    
            }
            if (x==1)
            {
                    switch (y)
                    {
                    case 0:  str = 0xC0; break;
                    case 1:  str = 0xC1; break;
                    case 2:  str = 0xC2; break;
                    case 3:  str = 0xC3; break;
                    case 4:  str = 0xC4; break;
                    case 5:  str = 0xC5; break;
                    case 6:  str = 0xC6; break;
                    case 7:  str = 0xC7; break;
                    case 8:  str = 0xC8; break;
                    case 9:  str = 0xC9; break;
                    case 10: str = 0xCA; break;
                    case 11: str = 0xCB; break;
                    case 12: str = 0xCC; break;
                    case 13: str = 0xCD; break;
                    case 14: str = 0xCE; break;
                    case 15: str = 0xCF; break;
                    }
            }
    
            Lcd_write_cmd(str);
    
    }

    odmin, 26 Октября 2011

    Комментарии (19)