자바, 610
class X{int n,c=0,t=0;public void static main(String[]a){n=Integer.parseInt(a[0]);String s,b,f,k,m,u;b="5L";s="3L";k="tank";u="Fill %s jug\n5L: %d, 3L: %d, T: %d";m="\nPour from %s jug into %s\n5L: %d, 3L: %d, T: %d";f=u+m;for(;n>4;)z(f,2,5,b,5,0,t,b,k,0,0,t+=5);while(n!=0){if(n==1)z(f+f+m,5,1,s,0,3,t,s,b,3,0,t,s,3,3,t,s,b,5,1,t,s,k,5,0,t+1);if(n==3)z(f,2,3,s,0,3,t,s,k,0,0,t+3);z(f+m,3,2,b,5,0,t,b,s,2,3,t,b,k,0,3,t+=2);if(n==2)z("Empty 3L jug\n5L: 0, 3L: 0,T: %d",1,0,t)}z("Volume measured out in %d turns",0,0,c)}void z(String s,int o,int w,Object...a){c+=o;n-=w;System.out.println(String.format(s,a))}}
나는 Sumedh 의 해결책을 가져 갔다 를 쳤다. 나는 의견에 그것을 넣고 싶었지만 내 명성은 충분하지 않다 :
골퍼가 없습니다 :
class X{
int n,c=0,t=0;
public void static main(String[] a){
n=Integer.parseInt(a[0]);
String s,b,f,k,m,u;
b="5L";
s="3L";
k="tank";
u="Fill %s jug\n5L: %d, 3L: %d, T: %d";
m="\nPour from %s jug into %s\n5L: %d, 3L: %d, T: %d";
f=u+m;
for(;n>4;)z(f,2,5,b,5,0,t,b,k,0,0,t+=5);
while(n!=0)
{
if(n==1)z(f+f+m,5,1,s,0,3,t,s,b,3,0,t,s,3,3,t,s,b,5,1,t,s,k,5,0,t+1);
if(n==3)z(f,2,3,s,0,3,t,s,k,0,0,t+3);
z(f+m,3,2,b,5,0,t,b,s,2,3,t,b,k,0,3,t+=2);
if(n==2)z("Empty 3L jug\n5L: 0, 3L: 0,T: %d",1,0,t);
}
z("Volume measured out in %d turns",0,0,c);
}
void z(String s,int o, int w,Object... a){
c+=o;
n-=w;
System.out.println(String.format(s,a));
}
}
주의 : 그것은 첫 번째 실행에서만 작동합니다. 다시 실행하면 전역 변수로 인해 결과가 잘못됩니다.
다음 버전은 안전하지만 610에서 612로 2 문자를 잃습니다.
class X{
int n,c,t;
public void static main(String[] a){
n=Integer.parseInt(a[0]);
String s,b,f,k,m,u;
t=c=0;
b="5L";
s="3L";
k="tank";
u="Fill %s jug\n5L: %d, 3L: %d, T: %d";
m="\nPour from %s jug into %s\n5L: %d, 3L: %d, T: %d";
f=u+m;
for(;n>4;)z(f,2,5,b,5,0,t,b,k,0,0,t+=5);
while(n!=0)
{
if(n==1)z(f+f+m,5,1,s,0,3,t,s,b,3,0,t,s,3,3,t,s,b,5,1,t,s,k,5,0,t+1);
if(n==3)z(f,2,3,s,0,3,t,s,k,0,0,t+3);
z(f+m,3,2,b,5,0,t,b,s,2,3,t,b,k,0,3,t+=2);
if(n==2)z("Empty 3L jug\n5L: 0, 3L: 0,T: %d",1,0,t);
}
z("Volume measured out in %d turns",0,0,c);
}
void z(String s,int o, int w,Object... a){
c+=o;
n-=w;
System.out.println(String.format(s,a));
}
}
N = 69에 대한 샘플 출력 :
Fill 5L jug
5L: 5, 3L: 0, T: 0
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 5
Fill 5L jug
5L: 5, 3L: 0, T: 5
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 10
Fill 5L jug
5L: 5, 3L: 0, T: 10
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 15
Fill 5L jug
5L: 5, 3L: 0, T: 15
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 20
Fill 5L jug
5L: 5, 3L: 0, T: 20
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 25
Fill 5L jug
5L: 5, 3L: 0, T: 25
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 30
Fill 5L jug
5L: 5, 3L: 0, T: 30
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 35
Fill 5L jug
5L: 5, 3L: 0, T: 35
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 40
Fill 5L jug
5L: 5, 3L: 0, T: 40
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 45
Fill 5L jug
5L: 5, 3L: 0, T: 45
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 50
Fill 5L jug
5L: 5, 3L: 0, T: 50
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 55
Fill 5L jug
5L: 5, 3L: 0, T: 55
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 60
Fill 5L jug
5L: 5, 3L: 0, T: 60
Pour from 5L jug into tank
5L: 0, 3L: 0, T: 65
Fill 5L jug
5L: 5, 3L: 0, T: 65
Pour from 5L jug into 3L
5L: 2, 3L: 3, T: 65
Pour from 5L jug into tank
5L: 0, 3L: 3, T: 67
Empty 3L jug
5L: 0, 3L: 0,T: 67
Fill 5L jug
5L: 5, 3L: 0, T: 67
Pour from 5L jug into 3L
5L: 2, 3L: 3, T: 67
Pour from 5L jug into tank
5L: 0, 3L: 3, T: 69
Volume measured out in 33 turns