1. C++ / Говнокод #17949

    +46

    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
    #include <Windows.h>
    #include <stdio.h> 
    #include <stdlib.h>
    #include <math.h>
    #include <iostream>
    #include <fstream>
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    
    
    double f(double x, double y)
    {
    	return y*y-2*x;
    }
    
    double f2(double x)
    {
    	return  sqrt(2*x+1);
    }
    
    int main(void) {
    	std::ofstream out;
    	out.open("out.txt");
    
    	double xn = 0, yn = 1, a = 0, b = 1, h = 0.2, x, y, n;
    	int i;
    	n = (b - a) / h;
    	y = yn;
    	x = a;
    
    	printf("x[0]=%.4f  ", x);
    	printf("y[0]=%.4f\n\n", y);
    	double k1, k2, k3, k4, dy, y1;
    	
    	cout << " i   " << "x[i]     " << "y[i]     " << "y[x[i]]  " << "E" << endl;
    
    	for (i = 1; i <= n; ++i)
    
    	{
    		x = xn + i*h;
    		k1 = h*f(x, y);
    		k2 = h*f((x + (h / 2)), (y + (1 / 2 * k1)));
    		k3 = h*f((x + (h / 2)), (y + (1 / 2 * k2)));
    		k4 = h*f((x + h), (y + k3));
    		dy = (k1 + 2 * k2 + 2 * k3 + k4) / 6;
    		y = y + dy;
    		y1 = f2(x);
    
    
    		printf("%2d.  ", i);
    		printf("%.5f  ", x);
    		printf("%.5f  ", y);
    		printf("%.5f  ", y1);
    		printf("%.9f\n", abs(y-y1));	
    		
    		
    	
    	}
    
    	out << y1 << '\n'; 
    	out.close();
    	
    	
    	
    	return 0;
    }

    В out выводится только последнее значение y1.
    Сам цикл проходит (в данном случае) 5 раз
    Соответственно, 5 значений y1
    Как сделать, чтобы он показывал все пять значений?

    misha3977, 06 Апреля 2015

    Комментарии (15)
  2. Куча / Говнокод #17948

    +127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    Makefile:
    ARCH=i386
    ...
    CFLAGS="-m32 -march=pentium-m -O3"
    
    ...

    Других архитектур не существует?

    mittorn, 06 Апреля 2015

    Комментарии (39)
  3. Objective C / Говнокод #17947

    −425

    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
    [self.userView sd_setImageWithURL:[comment.sender avatarThumbnailURL] placeholderImage:[UIImage coloredAvatarWithId:[NSString stringWithFormat:@"%lld", comment.sender.idValue]
    																									 andName:comment.sender.firstName
    																									  ofSize:CGSizeMake (57, 57)]];
    
    	self.dateLabel.text = [self tsFromDate:comment.createdAt];
    
    	[self.dateLabel sizeToFit];
    
    	if (comment.sender == [SWCore account])
    	{
    		self.balloonImage.image = [[UIImage imageNamed:@"in_baloon"] resizableStretchedImageWithCapInsets:UIEdgeInsetsMake (20, 50, 20, 50)];
    
    		self.messageLabel.textColor = [UIColor colorWithWhite:.4f alpha:1.0f];
    
    		self.userView.left = 20;
    		self.balloonImage.right = 300;
    		self.dateLabel.right = self.balloonImage.right;
    		self.dateIcon.right = self.dateLabel.left - 3;
    	}
    	else
    	{
    		self.balloonImage.image = [[UIImage imageNamed:@"out_baloon"] resizableStretchedImageWithCapInsets:UIEdgeInsetsMake (20, 50, 20, 50)];
    
    		self.messageLabel.textColor = [UIColor whiteColor];
    
    		self.userView.right = 300;
    		self.balloonImage.left = 20;
    		self.dateIcon.left = self.balloonImage.left;
    		self.dateLabel.left = self.dateIcon.right + 3;
    	}

    Мастерское владение размерами

    shadeapps, 06 Апреля 2015

    Комментарии (156)
  4. C++ / Говнокод #17946

    +54

    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
    #include <iostream>
    
    using namespace std;
    
    int sumc(int n) {
    	int res = 0;
    	while (n != 0) {
    		int tmp = n % 10;
    		n /= 10;
    		res += tmp * tmp;
    	}
    	return res;
    }
    
    int main () {
    	freopen("input.txt", "rt", stdin);
    	freopen("output.txt", "wt", stdout);
    	int x;
    	cin >> x;
    	int i;
    	for (i = x + 1; sumc(i) % 7; ++i);
    	cout << i;
            //код рабочий, а в комментах изначальный говно-вариант
    	/*int a[5];
    	a[0]=0;
    	a[1]=0;
    	a[2]=0;
    	a[3]=0;
    	a[4]=0;
    	int n = 4;
    	while (x > 0) {
    		a[n] = x%10;
    		x=x/10;
    		n--;
    	}
    	while (1 == 1) {
    		if ((a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3]+a[4]*a[4])%7 == 0)
    			break;
    		a[n]++;
    		for (int j=n; n>0; j--) {if (a[j]=10) {
    			a[j-1]++; 
    			a[j] = 0;
    		};
    		};
    
    	};
    	int j=-1;
    	while (1) {
    
    		++j;
    		if (a[j] != 0) break;
    	};
    	for (int l=j; l<5; l++){
    		cout << a[l];
    	};*/
    	return 0;
    }

    код рабочий, а в комментах изначальный говно-вариант

    yury99, 06 Апреля 2015

    Комментарии (13)
  5. Pascal / Говнокод #17945

    +100

    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
    // функция создания случайного ключа для шифровки/дешивровки сообщения
    function keyCreate(): string;
    const
      alf: string = 'abcdefjhijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ0123456789';
    var
      i, k: integer;
      logName: string;
    begin
      logName := '';
      for i := 0 to 15 do
      begin
        k := RandomRange(1, 62);
        logName := logName + alf[k];
      end;
      Result := logname;
    end;

    Какой оригинальный подход.

    Cynicrus, 06 Апреля 2015

    Комментарии (35)
  6. C# / Говнокод #17944

    +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
    public JsonResult Autocomplete(string term)
            {
                var result = new List<KeyValuePair<string, string>>();
    
                IList<SelectListItem> List = new List<SelectListItem>();
                List.Add(new SelectListItem { Text = "test1", Value = "0" });
                List.Add(new SelectListItem { Text = "test2", Value = "1" });
                List.Add(new SelectListItem { Text = "test3", Value = "2" });
                List.Add(new SelectListItem { Text = "test4", Value = "3" });
    
                foreach (var item in List)
                {
                    result.Add(new KeyValuePair<string, string>(item.Value.ToString(), item.Text));            
                }
                var result3 = result.Where(s => s.Value.ToLower().Contains(term.ToLower())).Select(w => w).ToList();
                return Json(result3, JsonRequestBehavior.AllowGet);
            }

    Наткнулся на CodeProject.

    kasthack, 06 Апреля 2015

    Комментарии (0)
  7. Objective C / Говнокод #17943

    −352

    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
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    	UITableViewCell *cell = nil;
    
    	if (indexPath.row == self.titles.count - 1)
    	{
    		cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];
    
    		SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;
    
    		[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];
    
    		[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];
    
    		scell.settingIcon.visible = YES;
    
    		@weakify(self);
    		[scell.settingButton bk_addEventHandler:^(id sender) {
    			[UIAlertView bk_showAlertViewWithTitle:@"Logout"
    										   message:@"Do you want to logout?"
    								 cancelButtonTitle:@"NO"
    								 otherButtonTitles:@[@"YES"]
    										   handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
    											   @strongify(self);
    
    											   if (buttonIndex != 0)
    											   {
    												   [[SWCore instance] logout];
                                                       // fix
                                                       [SVProgressHUD show];
                                                       // end fix
    											   }
    										   }];
    		}                      forControlEvents:UIControlEventTouchUpInside];
    	}
    	else if (indexPath.row == self.titles.count - 2)
    	{
    		cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];
    
    		SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;
    
    		[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];
    
    		[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];
    
    		scell.settingIcon.visible = NO;
    
    		@weakify(self);
    		[scell.settingButton bk_addEventHandler:^(id sender) {
    
    			@strongify(self);
    			[self performSegueWithIdentifier:@"pushSettingsSegue" sender:nil];
    		}                      forControlEvents:UIControlEventTouchUpInside];
    	}
    	else
    	{
    		cell = [tableView dequeueReusableCellWithIdentifier:@"settingCell" forIndexPath:indexPath];
    
    		SWSettingCell *scell = (SWSettingCell *) cell;
    
    		scell.settingLabel.text = self.titles[indexPath.row];
    		[scell.settingIcon setImage:self.icons[indexPath.row]];
    
    		switch (indexPath.row)
    		{
    			case 0:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PROFILE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_profile_icon_on"] : [UIImage imageNamed:@"settings_profile_icon_off"];
    			}
    				break;
    
    			case 1:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_EVENTS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_events_button_on"] : [UIImage imageNamed:@"settings_events_button_off"];
    			}
    				break;
    
    			case 2:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHONE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_phone_button_on"] : [UIImage imageNamed:@"settings_phone_button_off"];
    			}
    				break;
    
    			case 3:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHOTOS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_photos_button_on"] : [UIImage imageNamed:@"settings_photos_button_off"];
    			}
    				break;
    
    			default:
    				break;
    		}
    
    		scell.settingSwitch.tag = indexPath.row;
    		[scell.settingSwitch bk_removeEventHandlersForControlEvents:UIControlEventValueChanged];

    Один из самых классных методов cellForRowAtIndexPath что я когда-либо видел

    shadeapps, 06 Апреля 2015

    Комментарии (11)
  8. Pascal / Говнокод #17941

    +128

    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
    program st1r;
    uses crt;
    var
    st:string;
    n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,i:integer;
    begin
    clrscr;
    n0:=0; n1:=0; n2:=0; n3:=0; n4:=0;
    n5:=0; n6:=0; n7:=0; n8:=0; n9:=0;
    Write('Введите строку, состоящую из цифр: ');
    Readln (st);
    for i:=1 to length (st) do
    begin
    if Pos('0',st[i])<>0 then n0:=n0+1;
    if Pos('1',st[i])<>0 then n1:=n1+1;
    if Pos('2',st[i])<>0 then n2:=n2+1;
    if Pos('3',st[i])<>0 then n3:=n3+1;
    if Pos('4',st[i])<>0 then n4:=n4+1;
    if Pos('5',st[i])<>0 then n5:=n5+1;
    if Pos('6',st[i])<>0 then n6:=n6+1;
    if Pos('7',st[i])<>0 then n7:=n7+1;
    if Pos('8',st[i])<>0 then n8:=n8+1;
    if Pos('9',st[i])<>0 then n9:=n9+1;
    end;
    
    Writeln ('Количество вхождений в строку из цифр ',st);
    Writeln ('0: ',n0);
    Writeln ('1: ',n1);
    Writeln ('2: ',n2);
    Writeln ('3: ',n3);
    Writeln ('4: ',n4);
    Writeln ('5: ',n5);
    Writeln ('6: ',n6);
    Writeln ('7: ',n7);
    Writeln ('8: ',n8);
    Writeln ('9: ',n9);
    readln(st);
    end.

    студенту было дано задание: "Для каждой цифры '0', '1', ... '9' подсчитать количество их вхождений в строку S".

    shipushek, 06 Апреля 2015

    Комментарии (72)
  9. PHP / Говнокод #17940

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
     * @param $password
     * @return bool
     */
    public function validatePassword($password)
    {
        return (strcmp($password, $this->getPassword() === 0));
    }

    x25, 06 Апреля 2015

    Комментарии (34)
  10. Pascal / Говнокод #17939

    +98

    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
    // Функция шифрования
    function encryptAecMessage(): string;
    var
      //  myCript: TSyna3Des;
      tmpKey: string;
      //encryptingStr: string;
      aProcess: TProcess;
      pubKeyPath: string;
    begin
      tmpKey := keyCreate();
      pubKeyPath := ExtractFileDir(ParamStr(0)) + '/workinkey/key2_rsa.pub';
      //  myCript := TSyna3Des.Create(tmpKey);
      //encryptingStr := myCript.EncryptCTR(msg);
      aProcess := TProcess.Create(nil);
      // openssl rsautl -in /home/maksim/test -out /home/maksim/Загрузки/Keys -inkey /home/maksim/key2_rsa.pub
      AProcess.CommandLine := 'echo ' + tmpKey +
        ' | openssl rsautl -in /home/maksim/test -out ' +
        '/home/maksim/Загрузки/Keys -inkey ' + pubKeyPath + ' -pubin -encrypt';
      Result := '';
    end;

    Вот такое кусок отборного кала нашёл в старой версии игрового сервера-)

    Cynicrus, 06 Апреля 2015

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