Hướng dẫn cho [HSG] TỪ ĐỐI XỨNG


Chỉ sử dụng khi thực sự cần thiết như một cách tôn trọng tác giả và người viết hướng dẫn này.

Chép code từ bài hướng dẫn để nộp bài là hành vi có thể dẫn đến khóa tài khoản.

Authors: pvhung

#include <bits/stdc++.h>
using namespace std;
string dn(string s){
    reverse(s.begin(), s.end());
    return s;
}
bool kt(string s){
    if(dn(s) == s){
        return true;
    }
    else{
        return false;
    }
}
int main() {
        freopen("TUDX.INP", "r", stdin);
    freopen("TUDX.OUT", "w", stdout);
    string s;
    getline(cin, s);
    string t;
    stringstream ss(s);
    vector<string> p;
    while(ss >> t){
        p.push_back(t);
    }
    vector<string> temp;
    for(int i=0; i<p.size(); i++){
        for(int j=0; j < p.size(); j++){
            string k = p[i]+p[j];
            if(kt(k) and i != j){
                temp.push_back(k);
            }
        }
    }
    sort(temp.begin(), temp.end());
    for(string x : temp){
        cout << x << ' ';
    }
    return 0;
}


Bình luận

Sắp xếp theo
Tải bình luận...

Không có bình luận nào.