problème | http://nabetani.sakura.ne.jp/hena/ord15elebubo/ |
---|---|
Ruby/C++/Python/C | http://qiita.com/cielavenir/items/3d147bdeebcadcb4e3d9 |
Ruby(Golf,Examen de l'algorithme de Nabeya) | http://qiita.com/cielavenir/items/732a3140efe3db571480 |
Swift | http://qiita.com/cielavenir/items/600e264d39c402b244c1 |
Le programme de notation Ver2 a été mis à jour. https://github.com/cielavenir/procon/commit/532bb24e1f91d44d0d2a41a2846368c578e9eef8
La version Ruby / C ++ / Python / C est disponible. Python fonctionne à la fois sur 2.7 / 3.3.
[Ajout 1]
hena15.rb
#!/usr/bin/env ruby
#http://qiita.com/Nabetani/items/cba03c96d1ea55f6e861
#http://nabetani.sakura.ne.jp/hena/ord15elebubo/
STDOUT.sync=true
while gets
s=''
a=$_.chomp.split('/').map{|e|('%032b'%e.to_i(16)).chars.map{|f|f=='1'}}
raise if a[0].size!=32||a[1].size!=32
i=0
while i<a[0].size
if !a[0][i]&&!a[1][i]
i+=1
elsif a[0][i]&&a[1][i]
if a[0][i+1]
if a[0][i+2]
s+='N'
i+=3
else
s+='R'
i+=2
end
elsif a[1][i+1]
if a[1][i+2]
s+='U'
i+=3
else
s+='L'
i+=2
end
end
elsif a[0][i]
if a[0][i+2]
s+='T'
i+=3
else #if a[1][i+2]
s+='Z'
i+=3
end
else
if a[0][i+2]
s+='S'
i+=3
else
s+='J'
i+=2
end
end
end
puts s
end
hena15.cpp
//http://qiita.com/Nabetani/items/cba03c96d1ea55f6e861
//http://nabetani.sakura.ne.jp/hena/ord15elebubo/
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<unsigned int> split_int(string &str, const char *delim){
vector<unsigned int> result;
int cutAt;
while( (cutAt = str.find_first_of(delim)) != str.npos ){
if(cutAt > 0){
result.push_back(strtoul(str.substr(0, cutAt).c_str(),NULL,16));
}
str = str.substr(cutAt + 1);
}
if(str.length() > 0){
result.push_back(strtoul(str.c_str(),NULL,16));
}
return result;
}
int main(){
string line;
int i,j;
for(;getline(cin,line);){
string s;
vector<unsigned int>v=split_int(line,"/");
vector<vector<int> >a(2);
for(i=0;i<2;i++){
a[i].resize(34);
for(j=0;j<32;j++)a[i][j]=(v[i]>>(31-j))&1;
}
for(i=0;i<32;){
if(!a[0][i]&&!a[1][i]){
i++;
}else if(a[0][i]&&a[1][i]){
if(a[0][i+1]){
if(a[0][i+2]){
s+='N';
i+=3;
}else{
s+='R';
i+=2;
}
}else if(a[1][i+1]){
if(a[1][i+2]){
s+='U';
i+=3;
}else{
s+='L';
i+=2;
}
}
}else if(a[0][i]){
if(a[0][i+2]){
s+='T';
i+=3;
}else{ //if a[1][i+2]
s+='Z';
i+=3;
}
}else{
if(a[0][i+2]){
s+='S';
i+=3;
}else{
s+='J';
i+=2;
}
}
}
cout<<s<<endl;
}
}
hena15.py
#!/usr/bin/env python
#http://qiita.com/Nabetani/items/cba03c96d1ea55f6e861
#http://nabetani.sakura.ne.jp/hena/ord15elebubo/
import sys
if sys.version_info[0]>=3: raw_input=input
def solve(s):
v=[int(x,16) for x in s.split('/')]
a=[ [((v[i]>>(31-j))&1)>0 for j in range(32)]+[False]*2 for i in range(2) ]
s=''
i=0
while i<32:
if not a[0][i] and not a[1][i]:
i+=1
elif a[0][i] and a[1][i]:
if a[0][i+1]:
if a[0][i+2]:
s+='N'
i+=3
else:
s+='R'
i+=2
elif a[1][i+1]:
if a[1][i+2]:
s+='U'
i+=3
else:
s+='L'
i+=2
elif a[0][i]:
if a[0][i+2]:
s+='T'
i+=3
else:
s+='Z'
i+=3
else:
if a[0][i+2]:
s+='S'
i+=3
else:
s+='J'
i+=2
print(s)
sys.stdout.flush()
try:
while True:
s=raw_input()
solve(s)
except EOFError:
pass
hena15.c
//http://qiita.com/Nabetani/items/cba03c96d1ea55f6e861
//http://nabetani.sakura.ne.jp/hena/ord15elebubo/
#include <stdio.h>
unsigned int v[2];
int a[2][34];
int main(){
int i,j;
for(;~scanf("%08x/%08x",v,v+1);){
for(i=0;i<2;i++){
for(j=0;j<32;j++)a[i][j]=(v[i]>>(31-j))&1;
}
for(i=0;i<32;){
if(!a[0][i]&&!a[1][i]){
i++;
}else if(a[0][i]&&a[1][i]){
if(a[0][i+1]){
if(a[0][i+2]){
putchar('N');
i+=3;
}else{
putchar('R');
i+=2;
}
}else if(a[1][i+1]){
if(a[1][i+2]){
putchar('U');
i+=3;
}else{
putchar('L');
i+=2;
}
}
}else if(a[0][i]){
if(a[0][i+2]){
putchar('T');
i+=3;
}else{ //if a[1][i+2]
putchar('Z');
i+=3;
}
}else{
if(a[0][i+2]){
putchar('S');
i+=3;
}else{
putchar('J');
i+=2;
}
}
}
puts("");fflush(stdout);
}
}