From 051b3d7f663aea4e10151c8d7ef25ce3f404ea64 Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Wed, 25 Apr 2018 15:17:15 +0800 Subject: 2.2 subset, runround, lamps --- 2.2/runround.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 2.2/runround.c (limited to '2.2/runround.c') diff --git a/2.2/runround.c b/2.2/runround.c new file mode 100644 index 0000000..498b579 --- /dev/null +++ b/2.2/runround.c @@ -0,0 +1,72 @@ +/* +ID: mytbk921 +LANG: C +TASK: runround +*/ + +#include +#include + +int runround(unsigned int x) +{ + unsigned int msd, lsd, last, t; + int next[10]; + int map[10]; + int i; + + for (i=0; i<10; i++) map[i] = 0; + + lsd = x % 10; + if (lsd == 0) return 0; + last = lsd; + map[lsd] = 1; + x /= 10; + while (x>=10) { + t = x % 10; + if (map[t] || t==0) return 0; + map[t] = 1; + next[t] = last; + last = t; + x /= 10; + } + msd = x; + map[msd] = 1; + next[msd] = last; + next[lsd] = msd; + + last = msd; + do { + if (map[last]) + map[last] = 0; + else + return 0; + t = last; + for (i=0; i