1. Java / Говнокод #25998

    +1

    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
    import java.util.Scanner;
    
    public class ComputeTax {
    
    public static void main(String[] args) {
    // Create a Scanner
    Scanner input = new Scanner(System.in);
    
    // Prompt the user to enter filing status
    System.out.print(
        "(0-single filer, 1-married jointly or qualifying widow(er)",
        + "\n2-married separately, 3-head of household)\n" +
        "Enter the filing status: ");
    int status = input.nextInt();
    
    // Prompt the user to enter taxable income
    System.out.print("Enter the taxable income: ");
    double income = input.nextDouble();
    
    // Compute tax
    double tax = 0;
    
    if (status == 0) {// Compute tax for single filers
        if (income <= 8350)
              tax = income * 0.10;
        else if (income <= 33950)
              tax = 8350 * 0.10 + (income - 8350) * 0.15;
        else if (income <= 82250)
              tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
             (income - 33950) * 0.25;
        else if (income <= 171550)
              tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
             (82250 - 33950) * 0.25 + (income - 82250) * 0.28;
        else if (income <= 372950)
              tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
              (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
              (income - 171550) * 0.33;
        else
              tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
             (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
             (372950 - 171550) * 0.33 + (income - 372950) * 0.35;
    }
    else if (status == 1) {
    // Left as exercise
    // Compute tax for married file jointly or qualifying widow(er)
    }
    else if (status == 2) {
    // Compute tax for married separately
    // Left as exercise
    }
    else if (status == 3) {
    // Compute tax for head of household
    // Left as exercise
    }
    else {
        System.out.println("Error: invalid status");
        System.exit(1);
    }
    // Display the result
    System.out.println("Tax is " + (int)(tax * 100) / 100.0);
    
    }

    Ksyrx, 26 Октября 2019

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

    +2

    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
    // https://godbolt.org/z/dMT7v3
    
    unsigned div_eq(unsigned a, unsigned b)
    {
      ALWAYS_TRUE(a == b);
      return a/b;
    }
    
    unsigned div(unsigned a, unsigned b)
    {
      return a/b;
    }
    
    
    int test_array(unsigned char a[10])
    {
      for (int i = 1; i < 10; i++)
      {
        ALWAYS_TRUE(a[i-1] <= a[i]);
      }
      return a[0] <= a[2];
    }

    Refinement type
    Можно этой хуйней ассерты позаменять попробовать, и компилятор возможно что-то сможет за счет этого соптимизировать

    j123123, 26 Октября 2019

    Комментарии (6)
  3. Haskell / Говнокод #25996

    0

    1. 1
    2. 2
    3. 3
    4. 4
    f :: [Int] -> [Int]
    f [] = []
    f [a] = []
    f (a:b:lst) = b: f lst

    Как вытащить каждый второй элемент из массива.

    bot, 26 Октября 2019

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    private List<string> StrSplit(string str)
    {
        if (!string.IsNullOrEmpty(str))
            return str.Split(new char[] { ',', ';', ':' }, StringSplitOptions.RemoveEmptyEntries).ToList();
        return null;
    }

    m_sandman, 25 Октября 2019

    Комментарии (14)
  5. C# / Говнокод #25994

    0

    1. 1
    2. 2
    3. 3
    string log = pair;
    log += ":";
    log += new string(Convert.ToChar(32), 21 - pair.Length); /*spaces*/

    m_sandman, 25 Октября 2019

    Комментарии (4)
  6. JavaScript / Говнокод #25993

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    const getSizeString = (size: number) => {
        const mesuarments = ["Б", "кБ", "МБ", "ГБ"];
        let i = 0;
        for (; size/1024 > 1; size /= 1024, i++)
            ;
    
        return ${Math.floor(size) === size ? size : (size).toFixed(1)} ${mesuarments[i]};
    }

    m_sandman, 25 Октября 2019

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

    0

    1. 1
    let res: boolean = result.lmr_customertype === typeOfSaleValue ? false : true;

    m_sandman, 25 Октября 2019

    Комментарии (7)
  8. C++ / Говнокод #25991

    0

    1. 1
    2. 2
    3. 3
    4. 4
    char (&getArray())[11] {
      static char arr[] = "1234567890";
      return arr;
    }

    Как вернуть массив из функции в C/C++

    На самом деле нет: возвращается ссылка

    Elvenfighter, 24 Октября 2019

    Комментарии (97)
  9. C# / Говнокод #25990

    0

    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
    public class HttpQueryNameValueCollection : NameValueCollection
        {
            private ParallelLoopResult _parallelLoopResult;
    
            public override string ToString()
            {
                List<string> result;
                result = new List<string>();
                _parallelLoopResult = Parallel.ForEach(AllKeys, p =>
                {
                    if (BaseGet(p) != null)
                        result.Add(p + "=" + Get(p));
                });
                return string.Join("&", result);
            }
        }

    Формирование ссылки с query-параметрами недостаточно быстро, поэтому нужно это сделать в параллель :D

    adoconnection, 24 Октября 2019

    Комментарии (13)
  10. C++ / Говнокод #25989

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    // This concept tests whether 't + u' is a valid expression
    template<typename T, typename U>
    concept can_add = requires(T t, U u) { t + u; };
     
    // The function is only a viable candidate if 't + u' is a valid expression
    template<typename T, typename U> requires can_add<T, U>
    auto add(T t, U u)
    {
     return t + u;
    }

    ого чо есть

    MAPTbIwKA, 24 Октября 2019

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