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

    +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
    #include<stdio.h>
    int main()
    {
    	int a;
    	printf("Vvedite svoy vozrast (0-200 let)");
    	scanf("%d",&a);
    	if ((a==11)||(a==12)||(a==13)||(a==14)){printf("mne %d let",a); return 0;}
    	if ((a==111)||(a==112)||(a==113)||(a==114)){printf("mne %d let",a); return 0;}
    	if (a%10==1){printf("mne %d god",a); return 0;}
    	if (a%10==2){printf("mne %d goda",a); return 0;}
    	if (a%10==3){printf("mne %d goda",a); return 0;}
    	if (a%10==4){printf("mne %d goda",a); return 0;}
    	if ((a%10==0)||(a%10==5)||(a%10==6)||(a%10==7)||(a%10==8)||(a%10==9)){printf("mne %d let",a); return 0;}
    	return 0;
    }

    Программа выводит год/года/лет. То есть возраст синтаксически правильно. Вопрос. Это как-нибудь можно написать покороче? Это считается говнокодом?

    ForEveR, 09 Июня 2010

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

    +129

    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
    #include <iostream>
    #include <string.h>
    using namespace std;
    int strsearch(char* from, char* what);
    int getnumberafter(char* from, char* what);
    int strch(char* a, char* b, int pos);
    
    int strsearch(char* from, char* what)
    {
        int n=strlen(from)-strlen(what)+1;
        int i;
        for(i=0; i<n; i++)
    	if(strch(from, what, i)==strlen(what)) return i;
        return 0;
    }
    int getnumberafter(char* from, char* what)
    {
        int p, ret=0;
        if((p=strsearch(from,what))==0) return 0;
        p+=strlen(what);
        while(from[p]<'0'&&from[p]>'9')
        {
    	p++;
    	if(p>=strlen(from)) return 0;
        }
        while(from[p]>='0'&&from[p]<='9'&&p<strlen(from))
        {
    	ret=ret*10+(from[p++]-'0');
        }
        return ret;
    }
    int strch(char* a, char* b, int pos)
    {
        int i,n=min(strlen(a)-pos,strlen(b));
        for(i=0; i<n; i++)
    	if(a[i+pos]!=b[i]) return i;
        return i;
    }
    int main(int argc, char* argv[])
    {
        int i;
        double max=1,vol=0;
        for(i=0; i<argc; i++)
        {
    	cout << i << ": " << argv[i] << endl;
    	if(strch(argv[i],"type",0)==4) {  max=getnumberafter(argv[i],"max=");}
    	if(strch(argv[i],"values",0)==6) { vol=(getnumberafter(argv[i],"=")+getnumberafter(argv[i],","))/2;}
        }
        cout << vol/max << endl;
        return 0;
    }

    Задача из чего-то типа этого:
    numid=2,iface=MIXER,name='Master Playback Volume'
    ; type=INTEGER,access=rw---R--,values=2,min=0,max=31,step=0
    : values=31,31
    | dBscale-min=-46.50dB,step=1.50dB,mute=0
    Получить значение в процентах.
    #./a.out `amixer cget numid=2`
    0,67

    Tanger, 08 Июня 2010

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

    +137

    1. 1
    strncat (dstring, " ", 512);

    Калифорнийский код, простенько, но со вкусом. Сам не с первого раза понял в чём дело ;-)

    raorn, 08 Июня 2010

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

    +135

    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
    void init(void)
    {
    	int i,j;
    
    	setup();
    	if (!fork())
    		_exit(execve("/bin/update",NULL,NULL));
    	(void) open("/dev/tty0",O_RDWR,0);
    	(void) dup(0);
    	(void) dup(0);
    	printf("%d buffers = %d bytes buffer space\n\r",NR_BUFFERS,
    		NR_BUFFERS*BLOCK_SIZE);
    	printf(" Ok.\n\r");
    	if ((i=fork())<0)
    		printf("Fork failed in init\r\n");
    	else if (!i) {
    		close(0);close(1);close(2);
    		setsid();
    		(void) open("/dev/tty0",O_RDWR,0);
    		(void) dup(0);
    		(void) dup(0);
    		_exit(execve("/bin/sh",argv,envp));
    	}
    	j=wait(&i);
    	printf("child %d died with code %04x\n",j,i);
    	sync();
    	_exit(0);	/* NOTE! _exit, not exit() */
    }

    Говно, вошедшее в историю.

    avaaron, 03 Июня 2010

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

    +141

    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
    for (int x=0; x < TANK_SIZE; x++)
    
    	{
    
    		for (int y=0; y < TANK_SIZE; y++)
    
    		{
    
    			*((Uint32 *)(((Uint8 *)player_surface[DOWN]->pixels) + (TANK_SIZE - y - 1) * player_surface[DOWN]->pitch + (TANK_SIZE - x - 1) * player_surface[DOWN]->format->BytesPerPixel)) = *((Uint32 *)(((Uint8 *)player_surface[LEFT]->pixels) + (TANK_SIZE - x - 1) * player_surface[LEFT]->pitch + y * player_surface[LEFT]->format->BytesPerPixel)) = *((Uint32 *)(((Uint8 *)player_surface[RIGHT]->pixels) + x * player_surface[RIGHT]->pitch + (TANK_SIZE - y - 1) * player_surface[RIGHT]->format->BytesPerPixel)) = *((Uint32 *)(((Uint8 *)player_surface[UP]->pixels) + y * player_surface[UP]->pitch + x * player_surface[UP]->format->BytesPerPixel));
    
    			*((Uint32 *)(((Uint8 *)enemy_surface[DOWN]->pixels) + (TANK_SIZE - y - 1) * enemy_surface[DOWN]->pitch + (TANK_SIZE - x - 1) * enemy_surface[DOWN]->format->BytesPerPixel)) = *((Uint32 *)(((Uint8 *)enemy_surface[LEFT]->pixels) + (TANK_SIZE - x - 1) * enemy_surface[LEFT]->pitch + y * enemy_surface[LEFT]->format->BytesPerPixel)) = *((Uint32 *)(((Uint8 *)enemy_surface[RIGHT]->pixels) + x * enemy_surface[RIGHT]->pitch + (TANK_SIZE - y - 1) * enemy_surface[RIGHT]->format->BytesPerPixel)) = *((Uint32 *)(((Uint8 *)enemy_surface[UP]->pixels) + y * enemy_surface[UP]->pitch + x * enemy_surface[UP]->format->BytesPerPixel));
    
    			
    
    		}
    
    	}

    dageru, 03 Июня 2010

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

    +132

    1. 1
    2. 2
    3. 3
    if ((strlen == 0) && (key ==BNS_CLR_K || key ==WISE_K_BSPACE))
    				;
    else

    aljosha, 03 Июня 2010

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

    +130

    1. 1
    2. 2
    3. 3
    #if defined (CAMCORDER_FEATURE_SUPPORT_VIEW_MODE)
    //		case SETTING_VIEW_MODE:	
    #endif

    aljosha, 03 Июня 2010

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if(TouchRegist && !gIsCleanView && !gChangeZoom &&!gChangeBrightness)
    			if( TouchRegist && gChangeZoom)
    			{
    				...
    			}	
    			break;

    aljosha, 03 Июня 2010

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

    +103

    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
    /*    Copyright 2009 10gen Inc.
     *
     *    Licensed under the Apache License, Version 2.0 (the "License");
     *    you may not use this file except in compliance with the License.
     *    You may obtain a copy of the License at
     *
     *    http://www.apache.org/licenses/LICENSE-2.0
     *
     *    Unless required by applicable law or agreed to in writing, software
     *    distributed under the License is distributed on an "AS IS" BASIS,
     *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     *    See the License for the specific language governing permissions and
     *    limitations under the License.
     */
    
    /* all the numbers that fit in a 4 byte string */
    const char bson_numstrs[1000][4] = {
        "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",  "8",  "9",
        "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
    	/* 105 строк поскипано */
        "980", "981", "982", "983", "984", "985", "986", "987", "988", "989",
        "990", "991", "992", "993", "994", "995", "996", "997", "998", "999",
    };

    Взято отсюда - http://github.com/mongodb/mongo-c-driver/blob/master/src/numbers.c . А это коммит - http://github.com/mongodb/mongo-c-driver/commit/0198225180a51e0b0b8a84f25b34b3047d3b9c80

    raorn, 02 Июня 2010

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

    +144

    1. 1
    2. 2
    3. 3
    bool somevar;
    //... ... ...
    if(somevar==true)doSomething();

    И это в книге, по которой учат детей.

    frp, 01 Июня 2010

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