Skip to content

Instantly share code, notes, and snippets.

@YSRKEN
Created September 28, 2015 14:26
Show Gist options
  • Save YSRKEN/ce7e09b62a7b7a6f6982 to your computer and use it in GitHub Desktop.
Save YSRKEN/ce7e09b62a7b7a6f6982 to your computer and use it in GitHub Desktop.
POH6+『「え、妻が松江?」松江Ruby会議07協賛 回文作成プログラミングコンテスト』 言語毎のコード一覧 ref: http://qiita.com/YSRKEN/items/7cbf185d309739381a40
#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);}
#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;}
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);}}
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());}}
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(""))});
<?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);?>
$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);
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])
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