Другие языки программирования и технологии

Помощь по задаче на языке C++

Приветствую всех, небольшое предисловие-
Я программистом быть не собираюсь, так как нашел себя в 3D графике, поэтому за книги по С++ не садился и нет желания, поэтому, пожалуйста, помогите решить задачу:
__________________________________________________________________________________
Предлагается ввести строку A (ввод осуществляется нажатием клавиши Enter), а затем строку В. После этого необходимо вывести обработанные строки.
1.Если ни один символ A не входит в B, то упорядочить символы A в алфавитном порядке; в остальных случаях упорядочить символы A в порядке, обратном к алфавитному.
__________________________________________________________________________________

Буду очень благодарен!
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
string line(const string& msg) {
string tmp;
cout << msg << ": ";
getline(cin, tmp);
return tmp;
}
set<char> box(const string& line) {
set<char> tmp;
for (auto value : line) tmp.insert(value);
return tmp;
}
int main() {
auto a = line("a");
const auto b = line("b");
const auto sa = box(a);
const auto sb = box(b);
vector<char> s(sa.size() < sb.size() ? sa.size() : sb.size());
set_intersection(sa.begin(), sa.end(), sb.begin(), sb.end(), s.begin());
if (!s.at(0)) sort(a.begin(), a.end());
else sort(a.begin(), a.end(), greater<>());
cout << "result: " << a << '\n';
system("pause");
}
Владимир Балицький
Владимир Балицький
78 875
Лучший ответ
#include <iostream>
#include <string>
#include <unordered_set>
#include <algorithm>
#include <functional>

bool hasOccurrences(const std::string& a, const std::string& b) {
const std::unordered_set<char> set(b.cbegin(), b.cend());

for (char item : a)
if (set.find(item) != set.cend())
return true;

return false;
}

int main() {
std::string a, b;
std::getline(std::cin, a);
std::getline(std::cin, b);

if (hasOccurrences(a, b))
std::sort(a.begin(), a.end(), std::greater<char>());
else
std::sort(a.begin(), a.end());

std::cout << a << '\n' << b << '\n';
return 0;
}
Конаев))) ))))
Конаев))) ))))
20 861
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>

int main( int argc, char * argv[] )
{
std::string a, b;
std::cin >> a >> b;

auto exists_in = []( const std::string & s ) { return [&s]( char c ) { return s.find( c ) != std::string::npos; }; };

const bool a_in_b = std::any_of( std::begin( b ), std::end( b ), exists_in( a ) );
std::sort( std::begin( a ), std::end( a ), a_in_b? std::function( std::greater<char>{} ) : std::less_equal<char>{} );

std::cout << "a: " << a << "\n"
<< "b: " << b;
}
DA
Daulet Alikulov
14 578
если 3D, то в Blender используется Python, который с помощью Cython можно превратить в C++..
заодно и знания в 3D подтянешь...
Иван Максимов
Иван Максимов
1 821