Skip to content

Instantly share code, notes, and snippets.

@torazuka
Last active December 17, 2015 04:49
Show Gist options
  • Save torazuka/5553803 to your computer and use it in GitHub Desktop.
Save torazuka/5553803 to your computer and use it in GitHub Desktop.
第10回オフラインリアルタイムどう書く 本番問題の解答
import static org.junit.Assert.assertEquals;
import org.junit.Test;
enum Masu {
A("BCDEFG"), B("HICAGS"), C("IJKDAB"), D("CKLMEA"), E("ADMNOF"), F("GAEOPQ"), G(
"SBAFQR"), H("TUIBSk"), I("UVJCBH"), J("VWXKCI"), K("JXYLDC"), L(
"KYZaMD"), M("DLabNE"), N("EMbcdO"), O("FENdeP"), P("QFOefg"), Q(
"RGFPgh"), R("jSGQhi"), S("kHBGRj"), T("!!UHk!"), U("!!VIHT"), V(
"!!WJIU"), W("!!!XJV"), X("W!!YKJ"), Y("X!!ZLK"), Z("Y!!!aL"), a(
"LZ!!bM"), b("Ma!!cN"), c("Nb!!!d"), d("ONc!!e"), e("POd!!f"), f(
"gPe!!!"), g("hQPf!!"), h("iRQg!!"), i("!jRh!!"), j("!kSRi!"), k(
"!THSj!");
private String dest;
Masu(String s) {
dest = s;
}
public char getDest(int n) {
return dest.charAt(n);
}
}
/**
* 問題: http://nabetani.sakura.ne.jp/hena/ord10haniwa/
*/
public class Haniwa {
public String solve(final String input) {
int[] dests = getDests(input);
String result = "A";
Masu start = Masu.valueOf(result);
for (int each : dests) {
char dest = start.getDest(each);
result += dest;
if (dest == '!') {
continue;
}
start = Masu.valueOf(String.valueOf(dest));
}
return result;
}
private int[] getDests(final String input) {
int[] result = new int[input.length()];
for (int i = 0; i < input.length(); i++) {
result[i] = Integer.valueOf(String.valueOf(input.charAt(i)));
}
return result;
}
private void test(String input, String expected) {
Haniwa haniwa = new Haniwa();
assertEquals(expected, haniwa.solve(input));
}
@Test
public void testName() throws Exception {
/* 0 */test("135004", "ACDABHS");
/* 1 */test("1", "AC");
/* 2 */test("33333120", "AENc!!b!M");
/* 3 */test("0", "AB");
/* 4 */test("2", "AD");
/* 5 */test("3", "AE");
/* 6 */test("4", "AF");
/* 7 */test("5", "AG");
/* 8 */test("4532120", "AFQPOEMD");
/* 9 */test("051455", "ABSHSj!");
/* 10 */test("23334551", "ADMb!cdeO");
/* 11 */test("22033251", "ADLKLa!ML");
/* 12 */test("50511302122", "AGSjkTHTU!VW");
/* 13 */test("000051", "ABHT!!!");
/* 14 */test("1310105", "ACDKJW!V");
/* 15 */test("50002103140", "AGSk!HU!IVIU");
/* 16 */test("3112045", "AEDKYXKC");
/* 17 */test("02021245535", "ABCIJW!JIHBS");
/* 18 */test("014204", "ABIBCIB");
/* 19 */test("255230", "ADAGAEA");
/* 20 */test("443501", "AFPefgQ");
/* 21 */test("022321", "ABCKLZ!");
/* 22 */test("554452", "AGRh!!Q");
/* 23 */test("051024", "ABSHTUH");
/* 24 */test("524002", "AGAFGSB");
/* 25 */test("54002441132", "AGQRjSRhRSGA");
/* 26 */test("11010554312", "ACJV!!UTkSHI");
/* 27 */test("23405300554", "ADMNEFOFGRi!");
/* 28 */test("555353201", "AGRih!gPQG");
/* 29 */test("22424105", "ADLMabaLD");
/* 30 */test("11340202125", "ACJKDCKJX!!J");
/* 31 */test("4524451", "AFQFPf!P");
/* 32 */test("44434234050", "AFPf!!e!!Pgh");
/* 33 */test("00554040132", "ABHk!j!i!jRG");
/* 34 */test("3440403", "AEOePfgf");
/* 35 */test("111130", "ACJW!XW");
/* 36 */test("21133343125", "ADKXYZ!a!Z!L");
/* 37 */test("353511", "AEFOPFA");
/* 38 */test("22204115220", "ADLZYLY!KY!X");
/* 39 */test("03013541", "ABABICBGB");
/* 40 */test("101344", "ACIVJCA");
/* 41 */test("2432541", "ADENbNdN");
/* 42 */test("45332242015", "AFQPedc!!NME");
/* 43 */test("215453", "ADKCAGF");
/* 44 */test("45540523454", "AFQh!i!RQg!!");
/* 45 */test("42434302545", "AFEOd!!ONOef");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment