Odpowiedź:
#include <iostream>
#include <vector>
#include <string>
std::vector<std::string> formatNames(const std::vector<std::string>& names) {
std::vector<std::string> formattedNames;
for (const auto& name : names) {
formattedNames.push_back("Mr. " + name);
}
return formattedNames;
int main() {
std::vector<std::string> names = {"Munny", "Nowak", "Doe"};
std::vector<std::string> formattedNames = formatNames(names);
for (const auto& name : formattedNames) {
std::cout << name << std::endl;
return 0;
PYTHON
def formatNames(names):
formattedNames = ["Mr. " + name for name in names]
return formattedNames
names = ["Munny", "Nowak", "Doe"]
formattedNames = formatNames(names)
for name in formattedNames:
print(name)
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
Odpowiedź:
#include <iostream>
#include <vector>
#include <string>
std::vector<std::string> formatNames(const std::vector<std::string>& names) {
std::vector<std::string> formattedNames;
for (const auto& name : names) {
formattedNames.push_back("Mr. " + name);
}
return formattedNames;
}
int main() {
std::vector<std::string> names = {"Munny", "Nowak", "Doe"};
std::vector<std::string> formattedNames = formatNames(names);
for (const auto& name : formattedNames) {
std::cout << name << std::endl;
}
return 0;
}
PYTHON
def formatNames(names):
formattedNames = ["Mr. " + name for name in names]
return formattedNames
names = ["Munny", "Nowak", "Doe"]
formattedNames = formatNames(names)
for name in formattedNames:
print(name)