Created
September 28, 2015 14:26
-
-
Save YSRKEN/ce7e09b62a7b7a6f6982 to your computer and use it in GitHub Desktop.
POH6+『「え、妻が松江?」松江Ruby会議07協賛 回文作成プログラミングコンテスト』 言語毎のコード一覧 ref: http://qiita.com/YSRKEN/items/7cbf185d309739381a40
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<stdio.h> | |
#include<stdlib.h> | |
#include<string.h> | |
#define f strcmp | |
char W[11],T[11],L[5001],C[10001],R[5001],w[1000][11];int j,l,N,i,c=0;void F(char *s,char *d){l=strlen(s);for(j=0;j<l;++j)d[j]=s[l - j - 1];d[l]='\0';}int main(void){scanf("%d",&N);for(i=0;i<N;++i){scanf("%s",W);F(W,T);if(f(W,T))strcpy(w[c],W),++c;else strcat(C,W);}qsort(w,c,11,f);for(i=0;i<c;++i){F(w[i],T);if(f(w[i],T)<0 &&bsearch(T,w,c,11,f))strcat(L,w[i]);}F(L,R);printf("%s%s%s\n",L,C,R);} |
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> | |
using namespace std;int main(void){string n,T,L="",C="",R="";multiset<string>w;cin>>n;while(cin>>T)w.insert(T);for(auto W:w){T=W;reverse(T.begin(),T.end());if(W==T)C+=W;if(W<T&&w.count(T)){L+=W;R=T+R;}}cout<<L+C+R<<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
using System;class a{static void Main(){string n=Console.ReadLine(),l="",c="",r="",v;string[]w=Console.In.ReadToEnd().Split('\n');Array.Sort(w);char[]u;foreach(var t in w){u=t.ToCharArray();Array.Reverse(u);v=new string(u);if(t==v)c+=t;if(t.CompareTo(v)<0&&Array.BinarySearch(w,v)>=0){l+=t;r=v+r;}}Console.WriteLine(l+c+r);}} |
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
import java.io.*;import java.util.*;class Main{public static void main(String[]args)throws Exception{BufferedReader a=new BufferedReader(new InputStreamReader(System.in));String t=a.readLine(),v,c="";StringBuffer d,l=new StringBuffer();TreeSet w = new TreeSet();while((t=a.readLine())!=null)w.add(t);Iterator b=w.iterator();while(b.hasNext()){v=(String)b.next();d=new StringBuffer(v);t=d.reverse().toString();if(v.equals(t))c+=v;if(v.compareTo(t)<0&&w.contains(t))l.append(v);}if(c.length()==5)c+=c+c+c+c+c+c;System.out.println(l+c+l.reverse());}} |
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
process.stdin.resume(),process.stdin.setEncoding("utf8"),process.stdin.on("data",function(s){for(w=s.split("\n"),n=parseInt(w[0]),w.shift(),w.sort(),T=L=C="",i=1;i<=n;i++)T=w[i].split("").reverse().join(""),T==w[i]?C+=T:w[i]<T&&w.indexOf(T)>=0&&(L+=w[i]);console.log(L+C+L.split("").reverse().join(""))}); |
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
<?php fscanf(STDIN,"%d\n",$n);$w=array();while(!feof(STDIN)){$w[]=trim(fgets(STDIN));}$c="";$l="";sort($w);foreach($w as $v){$r=strrev($v);if($r==$v){$c.=$v;}elseif($v<$r&&array_search($r,$w)){$l.=$v;}}echo $l.$c.strrev($l);?> |
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 = <STDIN>;while (<STDIN>){chomp($_);push(@w,$_);}$C=$L="";@w=sort(@w);foreach(@w){$T=reverse($_);$C=$C.$T if $T eq $_;if($_ lt $T&&grep{$_ eq $T}@w){$L=$L.$_;}}print $L.$C.reverse($L); |
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=int(input());w=[];exec('w+=[raw_input()];'*n);C=L="";w.sort(); | |
for V in w: | |
R=V[::-1] | |
if V==R:C+=V | |
if V<R and R in w:L+=V | |
print(L+C+L[::-1]) |
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