Last active
September 28, 2015 14:14
-
-
Save YSRKEN/cfe440da9067ce95f3e5 to your computer and use it in GitHub Desktop.
POH6+『「え、妻が松江?」松江Ruby会議07協賛 回文作成プログラミングコンテスト』 ゴルフ編 ref: http://qiita.com/YSRKEN/items/f19a91b53d985ed65e5b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <set> | |
#include <string> | |
#define R(S) reverse(S.begin(), S.end()) | |
using namespace std; | |
int main(void){ | |
int N; | |
string temp_word, center_word = "", all_word = ""; | |
multiset<string> word; | |
cin >> N; | |
while(cin >> temp_word){ | |
word.insert(temp_word); | |
} | |
for(auto it : word){ | |
temp_word = it; | |
R(temp_word); | |
if(it == temp_word) | |
center_word += temp_word; | |
else | |
if(word.count(temp_word) && it < temp_word) | |
all_word += it; | |
} | |
cout << all_word << center_word; | |
R(all_word); | |
cout << all_word << endl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(イベント終了まで封印) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<set> | |
#include<string> | |
#define R(S) reverse(S.begin(),S.end()) | |
using namespace std;int main(){int N;string T,C="",A="";multiset<string>W;cin>>N;while(cin>>T)W.insert(T);for(auto I:W){T=I;R(T);if(I==T)C+=T;else if(W.count(T)&&I<T)A+=I;}cout<<A<<C;R(A);cout<<A<<endl;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(イベント終了まで封印) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n=gets;w=ARGF.read.split.sort;c="";w.select!{|x|c+=x if(y=x.reverse)==x;x<y&&w.index(y)};s=w.join;puts s+c+s.reverse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment