CPPPROGLIB Telegram 6126
🦀 Транспиляция кода: от одного языка к другому

Представьте ситуацию: вы нашли идеальное решение на GitHub, но оно написано не на том языке. Или ваш руководитель прочитал статью о новом фреймворке, и теперь нужно переписывать всю кодовую базу. Знакомо?

Хорошая новость: современные LLM-модели отлично справляются с транспиляцией кода между языками программирования.


✏️ Промпт

Rewrite the following code in C++:

[Вставь свой код сюда]



🍴 Пример использования

# Исходный Python код

def count_words(text):
"""Count word frequency in text"""
words = text.lower().split()
freq = {}
for word in words:
freq[word] = freq.get(word, 0) + 1
return freq

# Пример использования
text = "hello world hello python world"
print(count_words(text))
# Output: {'hello': 2, 'world': 2, 'python': 1}


Результат:

#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>

std::map<std::string, int> count_words(const std::string& text) {
std::map<std::string, int> freq;
std::istringstream stream(text);
std::string word;

while (stream >> word) {
// Convert to lowercase
std::transform(word.begin(), word.end(), word.begin(), ::tolower);
freq[word]++;
}

return freq;
}

int main() {
std::string text = "hello world hello python world";
auto result = count_words(text);

for (const auto& [word, count] : result) {
std::cout << word << ": " << count << std::endl;
}

return 0;
}


Библиотека C/C++ разработчика


#буст
Please open Telegram to view this post
VIEW IN TELEGRAM
👍9👾1



tgoop.com/cppproglib/6126
Create:
Last Update:

🦀 Транспиляция кода: от одного языка к другому

Представьте ситуацию: вы нашли идеальное решение на GitHub, но оно написано не на том языке. Или ваш руководитель прочитал статью о новом фреймворке, и теперь нужно переписывать всю кодовую базу. Знакомо?

Хорошая новость: современные LLM-модели отлично справляются с транспиляцией кода между языками программирования.


✏️ Промпт

Rewrite the following code in C++:

[Вставь свой код сюда]



🍴 Пример использования

# Исходный Python код

def count_words(text):
"""Count word frequency in text"""
words = text.lower().split()
freq = {}
for word in words:
freq[word] = freq.get(word, 0) + 1
return freq

# Пример использования
text = "hello world hello python world"
print(count_words(text))
# Output: {'hello': 2, 'world': 2, 'python': 1}


Результат:

#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>

std::map<std::string, int> count_words(const std::string& text) {
std::map<std::string, int> freq;
std::istringstream stream(text);
std::string word;

while (stream >> word) {
// Convert to lowercase
std::transform(word.begin(), word.end(), word.begin(), ::tolower);
freq[word]++;
}

return freq;
}

int main() {
std::string text = "hello world hello python world";
auto result = count_words(text);

for (const auto& [word, count] : result) {
std::cout << word << ": " << count << std::endl;
}

return 0;
}


Библиотека C/C++ разработчика


#буст

BY Библиотека C/C++ разработчика | cpp, boost, qt


Share with your friend now:
tgoop.com/cppproglib/6126

View MORE
Open in Telegram


Telegram News

Date: |

Click “Save” ; As of Thursday, the SUCK Channel had 34,146 subscribers, with only one message dated August 28, 2020. It was an announcement stating that police had removed all posts on the channel because its content “contravenes the laws of Hong Kong.” As five out of seven counts were serious, Hui sentenced Ng to six years and six months in jail. Clear With Bitcoin down 30% in the past week, some crypto traders have taken to Telegram to “voice” their feelings.
from us


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM American