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

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #define IMAGE_BASE_RELOC_TYPE 0x0C
    #define IMAGE_BASE_RELOC_OFFSET 0x0FFF
    #define IMAGE_GET_BASE_RELOC_TYPE(entry) entry >> IMAGE_BASE_RELOC_TYPE
    #define IMAGE_GET_BASE_RELOC_OFFSET(entry) entry & IMAGE_BASE_RELOC_OFFSET
    
    __declspec(safebuffers) __declspec(noinline) DWORD mapping_code(LPVOID map_struct)
    {
    	auto map = static_cast<MM_DATA*>(map_struct);
    
    	auto base = map->base;
    
    	auto dos = reinterpret_cast<PIMAGE_DOS_HEADER>(base);
    	auto nt_headers = reinterpret_cast<PIMAGE_NT_HEADERS>(base + dos->e_lfanew);
    
    	auto opt_header = &nt_headers->OptionalHeader;
    	auto file_header = &nt_headers->FileHeader;
    
    	const bool has_entry_point = opt_header->AddressOfEntryPoint != 0;
    	auto dll_main = reinterpret_cast<DllMainFn>(base + opt_header->AddressOfEntryPoint);
    
    	auto load_library			= map->load_library;
    	auto get_proc_address		= map->get_proc_address;
    	auto virtual_protect		= map->virtual_protect;
    	auto rtl_add_function_table = map->rtl_add_function_table;
    	
    	auto reloc_dir = opt_header->DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
    	auto location_delta = reinterpret_cast<uintptr_t>(base) - static_cast<uintptr_t>(opt_header->ImageBase);
    	
    	if (location_delta && reloc_dir.Size)
    	{
    		auto reloc_begin = reinterpret_cast<PIMAGE_BASE_RELOCATION>(base + reloc_dir.VirtualAddress);
    		auto reloc_end = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<std::byte*>(reloc_begin) + reloc_dir.Size);
    
    		while (reloc_begin < reloc_end && reloc_begin->SizeOfBlock)
    		{
    			auto amount_of_entries = (reloc_begin->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(WORD);
    
    			auto entries = reinterpret_cast<PWORD>(reloc_begin + 1);
    
    			for (size_t i = 0; i < amount_of_entries; i++)
    			{
    				WORD type = IMAGE_GET_BASE_RELOC_TYPE(entries[i]);
    				WORD offset = IMAGE_GET_BASE_RELOC_OFFSET(entries[i]);
    
    				if (type == IMAGE_REL_BASED_DIR64)
    				{
    					uintptr_t* path_at = reinterpret_cast<uintptr_t*>(base + reloc_begin->VirtualAddress + offset);
    					*path_at += location_delta;
    				}
    			}
    			reloc_begin = reinterpret_cast<PIMAGE_BASE_RELOCATION>(reinterpret_cast<std::byte*>(reloc_begin) + reloc_begin->SizeOfBlock);
    		}
    	}
    
    	auto import_dir = opt_header->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
    
    	if (import_dir.Size)
    	{
    		auto import_desc = reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>(base + import_dir.VirtualAddress);
    
    		while (import_desc->Name)
    		{
    			auto module_name = reinterpret_cast<char*>(base + import_desc->Name);
    			HMODULE module = load_library(module_name);
    
    			if (!module)
    			{
    				map->status = LOAD_LIBRARY_FAILED;
    				return -2;
    			}
    
    			auto INT_TABLE = reinterpret_cast<PIMAGE_THUNK_DATA>(base + (import_desc->OriginalFirstThunk ? import_desc->OriginalFirstThunk : import_desc->FirstThunk));
    			auto IAT_TABLE = reinterpret_cast<PIMAGE_THUNK_DATA>(base + (import_desc->FirstThunk));
    
    			for (; INT_TABLE->u1.AddressOfData ; INT_TABLE++, IAT_TABLE++)
    			{
    				FARPROC address = IMAGE_SNAP_BY_ORDINAL(INT_TABLE->u1.Ordinal) ? 
    					get_proc_address(module, reinterpret_cast<char*>(IMAGE_ORDINAL(INT_TABLE->u1.Ordinal))) :
    					get_proc_address(module, reinterpret_cast<PIMAGE_IMPORT_BY_NAME>(base + INT_TABLE->u1.AddressOfData)->Name);
    
    				if (!address)
    				{
    					map->status = GET_PROC_ADDRESS_FAILED;
    					return -3;
    				}
    
    				IAT_TABLE->u1.Function = reinterpret_cast<uintptr_t>(address);
    			}
    			++import_desc;
    		}
    	}
    
    	auto delay_dir = opt_header->DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT];
    
    	if (delay_dir.Size)
    	{
    		auto delay_desc = reinterpret_cast<PIMAGE_DELAYLOAD_DESCRIPTOR>(base + delay_dir.VirtualAddress);
    
    		while (delay_desc->DllNameRVA)
    		{

    0xDEADBEEF, 09 Мая 2026

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

    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
    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
    namespace arangodb {
    class DatabaseFeature;
    
    struct IDatabaseGuard {
      virtual ~IDatabaseGuard() = default;
      [[nodiscard]] virtual TRI_vocbase_t& database() const noexcept = 0;
    };
    
    struct VocbaseReleaser {
      void operator()(TRI_vocbase_t* vocbase) const noexcept;
    };
    
    using VocbasePtr = std::unique_ptr<TRI_vocbase_t, VocbaseReleaser>;
    
    /// @brief Scope guard for a database, ensures that it is not
    ///        dropped while still using it.
    class DatabaseGuard final : public IDatabaseGuard {
     public:
      /// @brief create guard on existing db
      explicit DatabaseGuard(TRI_vocbase_t& vocbase);
    
      /// @brief create guard from existing VocbasePtr
      explicit DatabaseGuard(VocbasePtr vocbase);
    
      /// @brief create the guard, using a database id
      DatabaseGuard(DatabaseFeature& feature, TRI_voc_tick_t id);
    
      /// @brief create the guard, using a database name
      DatabaseGuard(DatabaseFeature& feature, std::string_view name);
    
      /// @brief return the database pointer
      TRI_vocbase_t& database() const noexcept final { return *_vocbase; }
      TRI_vocbase_t const* operator->() const noexcept { return _vocbase.get(); }
      TRI_vocbase_t* operator->() noexcept { return _vocbase.get(); }
    
     private:
      VocbasePtr _vocbase;
    };
    
    }  // namespace arangodb

    Виртуальное гавно!

    gnusmas, 19 Марта 2026

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

    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
    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
    #pragma GCC optimize("03")
    #include <bits/stdc++.h>
    #pragma GCC target("avx2,tune=native")
    using namespace std;
    int binxor(int a, int b) {
        if (b == 0) {
            return 0;
        }
        int t = binxor(a, b / 2);
        if (b % 2 == 0) {
            return t ^ t;
        } else {
            return t ^ t ^ a;
        }
    }
    vector<int> per(20);
    vector<int> res(binxor(1 << 20, numeric_limits<int>::max() + 2), -1);
    vector<int> need(binxor(1 << 20, numeric_limits<int>::max() + 2), 0);
    vector<int> gp(binxor(1 << 20, numeric_limits<int>::max() + 2), 1 << 30);
    int c = 0;
    int Trump = 0;
    inline void f(int i, int n, int w) {
        if (i == w) {
            for (int j = 0; j < w; j++) {
                if ((Trump >> (w - 1 - j)) & 1) {
                    gp[Trump] = min(gp[Trump], gp[Trump ^ (1 << (w - 1 - j))]);
                }
            }
            return;
        }
        f(i + 1, n, w);
        Trump ^= 1 << (w - 1 - i);
        f(i + 1, n, w);
        Trump ^= 1 << (w - 1 - i);
    }
    signed main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n, q, w;
        cin >> n >> q >> w;
        vector<string> s(n);
        for (auto &x : s) {
            cin >> x;
        }
        vector<int> ord(n);
        iota(ord.begin(), ord.end(), 0);
        sort(ord.begin(), ord.end(), [&](int x, int y) {
            return s[x] < s[y];
        });
        for (int i = 0; i < n; i++) {
            int Trump = 0;
            for (auto ch : s[ord[i]]) {
                Trump |= 1 << (ch - 'a');
            }
            gp[Trump] = min(gp[Trump], i);
        }
        f(0, n, w);
        for (int i = 0; i < q; ++i) {
            string t;
            cin >> t;
            int Harris = 0;
            for (auto ch : t) {
                Harris |= 1 << (ch - 'a');
            }
            int val = gp[((1 << w) - 1) ^ Harris];
            cout << (val >= n ? -1 : 1 + ord[val]) << "\n";
        }
        return 0;
    }

    Без комментариев

    letipetukh1, 13 Февраля 2026

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

    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
    const std::string programPath =
        "/root/CLionProjects/PetukhPlusPlus/program.petukh";
    
    const std::string lexerOutPath =
        "/root/CLionProjects/PetukhPlusPlus/res_lexer.txt";
    
    const std::string syntaxOutPath =
        "/root/CLionProjects/PetukhPlusPlus/res_syntax.txt";
    
    const std::string semanticOutPath =
        "/root/CLionProjects/PetukhPlusPlus/res_semantic.txt";
    
    const std::string polizOutPath =
        "/root/CLionProjects/PetukhPlusPlus/res_poliz.txt";

    Классика говнокода

    letipetukh1, 12 Февраля 2026

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

    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
    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
    cin >> N >> L >> T;
      total = 0;
      for (int i = 0; i < N; i++) {
        cin >> S[i] >> H[i] >> P[i];
        total += H[i] * P[i];
      }
      fix_order();
      for (int ind = 0; ind < N; ind++) {
        int len = ind + 1;
        set<pair<long long, int>> events, comps;
        vector<long long> sum_hp(len);
        copy(H, H + len, sum_hp.begin());
        sum_hp[ind] = 0;
        vector<int> ord(len);
        iota(ord.begin(), ord.end(), 0);
        sort(ord.begin(), ord.end(), [&](int i, int j) {
          return S[i] < S[j];
        });
        comps.emplace(T, -1);
        for (int i = 0; i < len; i++) {
          int j = i + 1;
          while (j < len && S[ord[i]] == S[ord[j]]) {
            sum_hp[ord[i]] += sum_hp[ord[j]];
            ++j;
          }
          comps.emplace(S[ord[i]], ord[i]);
          i = j - 1;
        }
        for (auto it = comps.begin(); next(it) != comps.end(); ++it) {
          long long dist = next(it)->first - it->first;
          int idx = it->second;
          if (sum_hp[idx] > 0) {
            events.emplace((dist + sum_hp[idx] - 1) / sum_hp[idx], idx);
          }
        }
        vector<bool> visited(len);
        vector<bool> added(len);
        long long good_sum = 0, last_time = 0, govno = T, rakom_bokom = 0;
        for (auto [spawn, i] : comps) {
          if (spawn >= S[ind] && i != -1) {
            good_sum += sum_hp[i];
            added[i] = true;
          }
        }
        auto Upd = [&](long long time) -> void {
          long long F = govno - S[ind] - rakom_bokom;
          if (F <= 0) {
            return;
          }
          long long r1 = clamp(F / (H[ind] + good_sum) + 1, last_time, time);
          long long r2 = good_sum == 0 ? time : clamp(F / good_sum + 1, last_time, time);
          dp_diff_i[last_time] += H[ind] * P[ind];
          dp_diff_i[r1] -= H[ind] * P[ind];
          dp_diff[r1] += F * P[ind];
          dp_diff[r2] -= F * P[ind];
          dp_diff_i[r1] -= good_sum * P[ind];
          dp_diff_i[r2] += good_sum * P[ind];
          last_time = time;
        };
        vector<bool> skip(len), finished(len);
        while (!events.empty()) {
          auto [time, i] = *events.begin();
          events.erase(events.begin());
          if (time > L) {
            break;
          }
          if (skip[i] || sum_hp[i] == 0) {
            continue;
          }
          Upd(time);
          auto it = comps.upper_bound({S[i], INT_MAX});
          if (it->second == -1 || finished[it->second]) {
            good_sum -= sum_hp[i];
            finished[i] = true;
            govno = S[i];
            continue;
          }
          if (!added[i] && it->second + sum_hp[i] * time >= S[ind]) {
            added[i] = true;
            good_sum += sum_hp[i];
            rakom_bokom += S[i] - S[ind];
          }
          sum_hp[i] += sum_hp[it->second];
          skip[it->second] = true;
          long long next_pos = next(it)->first;
          comps.erase(it);
          events.emplace(time + (next_pos - S[i] - sum_hp[i] * time + sum_hp[i] - 1) / sum_hp[i], i);
        }
        Upd(L + 1);
      }
      long long cur_diff = 0, cur_diff_i = 0;
      for (int i = 0; i <= L; i++) {
        cur_diff += dp_diff[i];
        cur_diff_i += dp_diff_i[i];
        dp[i] = cur_diff + cur_diff_i * i;
      }

    олимпиадное говно

    letipetukh1, 26 Января 2026

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

    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
    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
    #include <iostream>
    #include <type_traits>
    #include <mutex>
    #include <string>
    #include <memory>
    #include <vector>
    #include <chrono>
    
    void bad_function(void* data) {
       ///  НИКОГДА ТАК НЕ ПИШИ
        if (data) {
            std::cout << *(std::string*)data << "\n";
        }
    }
    
    template<typename T = std::string,
             typename Alloc = std::allocator<T>,
             typename = std::enable_if_t<std::is_constructible_v<T, const char*>>,
             typename Clock = std::chrono::high_resolution_clock,
             typename TimePoint = typename Clock::time_point>
    class GoodFunctionImpl {
    private:
        static std::recursive_mutex mtx_;
        Alloc alloc_;
        std::vector<T, Alloc> buffer_;
        std::string context_;
        TimePoint init_time_;
        
        template<typename U>
        using is_valid_type = std::conjunction<
            std::is_same<std::decay_t<U>, T>,
            std::is_constructible<T, U>
        >;
        
        void internal_log(const std::string& msg) {
            buffer_.push_back(T(msg.c_str()));
        }
        
    public:
        GoodFunctionImpl() : init_time_(Clock::now()) {
            internal_log("GoodFunctionImpl initialized");
        }
        
        template<typename U,
                 typename = std::enable_if_t<is_valid_type<U>::value>>
        decltype(auto) execute(U&& input) {
            std::lock_guard<std::recursive_mutex> lock(mtx_);
            
            internal_log("Processing started");
            
            T processed = std::forward<U>(input);
            
            auto duration = Clock::now() - init_time_;
            auto duration_ms = std::chrono::duration_cast<
                std::chrono::milliseconds>(duration).count();
            
            std::cout << processed << " (runtime: " 
                      << duration_ms << "ms)\n";
            
            internal_log("Processing completed");
            
            return processed;
        }
        
        size_t get_buffer_size() const { return buffer_.size(); }
    };
    
    template<typename T, typename Alloc, typename, typename Clock, typename TimePoint>
    std::recursive_mutex GoodFunctionImpl<T, Alloc, Clock, TimePoint>::mtx_;
    
    void good_function(const std::string& input) {
        // Пиши ВОТ ТАК
        // так делают все
        // это стабильно и надежно
        // так надо
        GoodFunctionImpl<> impl;
        auto result = impl.execute(input);
        
        std::cout << "Buffer entries: " 
                  << impl.get_buffer_size() << "\n";
    }

    lisp-worst-code, 06 Декабря 2025

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

    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
    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 makeShape(ShapeArguments shape)
    {
        if (shape.type == ShapeType::Square)
        {
            throw Square(shape);
        }
    
        if (shape.type == ShapeType::Cicle)
        {
            throw Circle(shape);
        }
    }
    
    void handleShape(ShapeArguments shape)
    {
        try
        {
            makeShape(shape);
        }
        catch (const Square& square)
        {
            // Work with square
        }
        catch (const Circle& circle)
        {
            // Work with circle
        }
    }

    factory

    kcalbCube, 25 Ноября 2025

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    SparseMatrix<double> mat(rows,cols);
    for (int k=0; k<mat.outerSize(); ++k)
      for (SparseMatrix<double>::InnerIterator it(mat,k); it; ++it)
      {
        it.value();
        it.row();   // row index
        it.col();   // col index (here it is equal to k)
        it.index(); // inner index, here it is equal to it.row()
      }

    Random access to the elements of a sparse object can be done through the coeffRef(i,j) function. However, this function involves a quite expensive binary search. In most cases, one only wants to iterate over the non-zeros elements. This is achieved by a standard loop over the outer dimension, and then by iterating over the non-zeros of the current inner vector via an InnerIterator. Thus, the non-zero entries have to be visited in the same order than the storage order.

    CHayT, 03 Сентября 2025

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

    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
    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
    // https://github.com/ggml-org/llama.cpp/blob/f4c3dd5daa3a79f713813cf1aabdc5886071061d/examples/simple/simple.cpp#L23
    
        // parse command line arguments
    
        {
            int i = 1;
            for (; i < argc; i++) {
                if (strcmp(argv[i], "-m") == 0) {
                    if (i + 1 < argc) {
                        model_path = argv[++i];
                    } else {
                        print_usage(argc, argv);
                        return 1;
                    }
                } else if (strcmp(argv[i], "-n") == 0) {
                    if (i + 1 < argc) {
                        try {
                            n_predict = std::stoi(argv[++i]);
                        } catch (...) {
                            print_usage(argc, argv);
                            return 1;
                        }
                    } else {
                        print_usage(argc, argv);
                        return 1;
                    }
                } else if (strcmp(argv[i], "-ngl") == 0) {
                    if (i + 1 < argc) {
                        try {
                            ngl = std::stoi(argv[++i]);
                        } catch (...) {
                            print_usage(argc, argv);
                            return 1;
                        }
                    } else {
                        print_usage(argc, argv);
                        return 1;
                    }
                } else {
                    // prompt starts here
                    break;
                }
            }
            if (model_path.empty()) {
                print_usage(argc, argv);
                return 1;
            }
            if (i < argc) {
                prompt = argv[i++];
                for (; i < argc; i++) {
                    prompt += " ";
                    prompt += argv[i];
                }
            }
        }

    Парсинг аргументов командной строки

    j123123, 16 Марта 2025

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

    0

    1. 1
    Мда... Какое же всё таки говнецо это Ваше США.

    3uMuCTOH, 04 Марта 2025

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