Другое С/С++ Вопрос - Ответ

AdCKuY_DpO4uLa

Адский дрочер
Друг
369
821
Как указать модификатор глобального поиска "g"?

C++:
boost::regex regular("([\\d+\\s+])");
 

MrEnderStail

Новичок
19
0
нужна помощь с кодом ( ниже ).
Задание :11 знаков после десятичной точки. Но я не пойму как получить 11 знаков после точки.

И если кто то знает скиньте руководство по типом данных( float double и тд. И как их использовать , комбинировать и тд)
дада:
#include <stdio.h>
#include <math.h>
#include <locale.h>

int m;
int Z;
int X;
int B;
int C;
float V;
; int main(void)
{
    setlocale(LC_CTYPE, "rus");
        printf("Введите m: ");
        scanf_s("%d", &m);
            B = pow(3 * m, 2);
            X = sqrt((B+4) - (24 * m));
            C = 3 * sqrt(m) - 2 / sqrt(m);
            V = X / C;
        printf("%d\n" ,X);
        printf("%d\n", C);
        printf("%f\n", V);
    return 0;
}
 

AdCKuY_DpO4uLa

Адский дрочер
Друг
369
821
нужна помощь с кодом ( ниже ).
Задание :11 знаков после десятичной точки. Но я не пойму как получить 11 знаков после точки.

И если кто то знает скиньте руководство по типом данных( float double и тд. И как их использовать , комбинировать и тд)
дада:
#include <stdio.h>
#include <math.h>
#include <locale.h>

int m;
int Z;
int X;
int B;
int C;
float V;
; int main(void)
{
    setlocale(LC_CTYPE, "rus");
        printf("Введите m: ");
        scanf_s("%d", &m);
            B = pow(3 * m, 2);
            X = sqrt((B+4) - (24 * m));
            C = 3 * sqrt(m) - 2 / sqrt(m);
            V = X / C;
        printf("%d\n" ,X);
        printf("%d\n", C);
        printf("%f\n", V);
    return 0;
}
C:
#include <stdio.h>
#include <math.h>

int main()
{
    double m, Z, X, B, C, V;
    
    printf("Введите m: ");
    scanf("%lf", &m);
    
    B = pow(3 * m, 2);
    X = sqrt((B + 4) - (24 * m));
    C = 3 * sqrt(m) - 2 / sqrt(m);
    V = X / C;
    
    printf("%0.11lf\n%0.11lf\n%0.11lf", X, C, V);
    
    return 0;
}
 

Dark_Knight

Me, me and me.
Друг
4,080
2,112
Ты про это?
1633206472552.png
 

DANIIL XPC

Известный
82
5
How can i remake this in c++ sf?
C++:
    sampRegisterChatCommand('kr', k1d)



function k1d(params)
    if params ~= nil then
        lua_thread.create(function()
                sampSendChat("text")
                wait(2000)
                sampSendChat("text2")
    end)
    end
end
 

legendabrn

Известный
Проверенный
121
171
How can i remake this in c++ sf?
C++:
    sampRegisterChatCommand('kr', k1d)



function k1d(params)
    if params ~= nil then
        lua_thread.create(function()
                sampSendChat("text")
                wait(2000)
                sampSendChat("text2")
    end)
    end
end
C++:
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS

#include <assert.h>
#include <thread>

#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"

SAMPFUNCS *SF = new SAMPFUNCS();

void CALLBACK k1d(std::string params)
{
    std::thread test([]()
    {
        SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "text");
        std::this_thread::sleep_for(std::chrono::milliseconds(2000));
        SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "text2");
    });
    test.detach();
}

void CALLBACK mainloop()
{
    static bool init = false;
    if (!init)
    {
        if (GAME == nullptr && GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME && !SF->getSAMP()->IsInitialized()) return;
        SF->getSAMP()->registerChatCommand("kr", k1d);
        init = true;
    }
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
    if(dwReasonForCall == DLL_PROCESS_ATTACH) SF->initPlugin(mainloop, hModule);
    return TRUE;
}
 
  • Злость
Реакции: Dark_Knight

kin4stat

mq-team · kin4@naebalovo.team
Всефорумный модератор
2,759
4,891
C++:
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS

#include <assert.h>
#include <thread>

#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"

SAMPFUNCS *SF = new SAMPFUNCS();

void CALLBACK k1d(std::string params)
{
    std::thread test([]()
    {
        SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "text");
        std::this_thread::sleep_for(std::chrono::milliseconds(2000));
        SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "text2");
    });
    test.detach();
}

void CALLBACK mainloop()
{
    static bool init = false;
    if (!init)
    {
        if (GAME == nullptr && GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME && !SF->getSAMP()->IsInitialized()) return;
        SF->getSAMP()->registerChatCommand("kr", k1d);
        init = true;
    }
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
    if(dwReasonForCall == DLL_PROCESS_ATTACH) SF->initPlugin(mainloop, hModule);
    return TRUE;
}
Ага, здарова UB
 

kin4stat

mq-team · kin4@naebalovo.team
Всефорумный модератор
2,759
4,891
самый красивый вариант
or
самый уебанский вариант
or
что-то между:

C++:
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"

#include <functional>
#include <chrono>
#include <list>

class Timer {
    struct TimerInfo {
        std::chrono::steady_clock::time_point start;
        std::chrono::milliseconds duration;
        std::function<void()> callback;

        TimerInfo(std::chrono::steady_clock::time_point s, std::chrono::milliseconds dur, std::function<void()> cb) : start(s), duration(dur), callback(cb) {}
    };

public:
    static Timer& Instance() {
        static Timer inst;
        return inst;
    }

    void Update() {
        using namespace std::chrono;
        for (auto it = timers.begin(); it != timers.end();) {
            auto& timer = *it;
            if (steady_clock::now() - timer.start > timer.duration) {
                timer.callback();
                timers.erase(it++);
            }
            else {
                ++it;
            }
        }
    }

    void AddTimer(std::function<void()> callback, std::chrono::milliseconds duration) {
        timers.emplace_back(std::chrono::steady_clock::now(), duration, callback);
    }

    std::list<TimerInfo> timers;
};

SAMPFUNCS *SF = new SAMPFUNCS();

void CALLBACK k1d(std::string params)
{
    using namespace std::chrono_literals;
    SF->getSAMP()->getChat()->AddChatMessage(0xFF00FF00, "text");
    Timer::Instance().AddTimer([] {
        SF->getSAMP()->getChat()->AddChatMessage(0xFFFF0000, "text2");
    }, 3s);
}

void CALLBACK mainloop()
{
    Timer::Instance().Update();
    static bool init = false;
    if (!init)
    {
        if (GAME == nullptr &&
            GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME &&
            !SF->getSAMP()->IsInitialized())
            return;
        SF->getSAMP()->registerChatCommand("kr", k1d);
        init = true;
    }
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID)
{
    if (dwReasonForCall == DLL_PROCESS_ATTACH) {
        SF->initPlugin(mainloop, hModule);
    }
    return TRUE;
}

P.S. код таймера был написан за 5 минут как proof of concept, кто хочет - оптимизируйте
 

kin4stat

mq-team · kin4@naebalovo.team
Всефорумный модератор
2,759
4,891
1. Посмотреть вложение 117271
Есть код, но увы он в некоторых числах работает не правильно, хелп плиз

#include <iostream>
using namespace std;
int main()
{
long long n;
int reverse=0, rem;
//cout<<"Enter a number: ";
cin>>n;
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
cout<<reverse<<endl;
//system("PAUSE");
return 0;
}
C++:
#include <string>
#include <algorithm>
#include <iostream>

int main() {
    std::string in{};
    std::cin >> in;
    bool negative = false;
    if (in[0] == '-') {
        negative = true;
        in = in.substr(1);
    }
    std::reverse(in.begin(), in.end());
    std::string out = std::to_string(std::stoll(in));
    if (negative) {
        out = "-" + out;
    }
    std::cout << out;
}
 
  • Нравится
Реакции: .deserve