PageRenderTime 123ms CodeModel.GetById 83ms app.highlight 34ms RepoModel.GetById 1ms app.codeStats 0ms

/SRM518-LargestSubsequence.go

https://code.google.com/
Go | 208 lines | 201 code | 6 blank | 1 comment | 11 complexity | 096d8bd58c88de281c8546d11707a14e MD5 | raw file
  1package main
  2
  3import (
  4	"fmt"
  5)
  6
  7func main() {
  8	check()
  9}
 10
 11func getLargest(s string) string {
 12	res := ""
 13	b := []byte(s)
 14	bi := 0
 15	for {
 16	label:
 17		if bi == len(b) {
 18			break
 19		}
 20		for i := byte('z'); i >= byte('a'); i-- {
 21			for j := bi; j < len(b); j++ {
 22				if b[j] == i {
 23					res += string(i)
 24					bi = j + 1
 25					goto label
 26				}
 27			}
 28		}
 29	}
 30	return res
 31}
 32
 33type iotype struct {
 34	arg, result string
 35}
 36
 37func check() {
 38	tests := []iotype{
 39		iotype{"test", "tt"},
 40		iotype{"a", "a"},
 41		iotype{"example", "xple"},
 42		iotype{"aquickbrownfoxjumpsoverthelazydog", "zyog"},
 43		iotype{"zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccaa", "zzyyxxwwvvuuttssrrqqppoonnmmllkkjjiihhggffeeddccaa"},
 44		iotype{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
 45		iotype{"dtbsthudhqvqxxmqxusna", "xxxusna"},
 46		iotype{"ddifmyqoojkeyiee", "yyiee"},
 47		iotype{"mhdsrshovdancelcihqcrsfdfvsrgstsxvzh", "zh"},
 48		iotype{"vslheaxwhc", "xwhc"},
 49		iotype{"lumguibrvvnvwnwhzail", "zl"},
 50		iotype{"hctiodxvzmllfgri", "zri"},
 51		iotype{"zjxhngujgnhlqpkfwuseqzcrxzjsltdekwoiklfgkywdpj", "zzzywpj"},
 52		iotype{"sw", "w"},
 53		iotype{"xpmjapuoeqouquzjnuyxzajdrn", "zzrn"},
 54		iotype{"rkkpfgidl", "rpl"},
 55		iotype{"phqhlsucxtebkyemlykfmzlznmopuhgvdambgpiglo", "zzvpo"},
 56		iotype{"bzslcgclmgzulhxdrhkogsbuofrjrapcdutisprkrvosug", "zzxvug"},
 57		iotype{"puluqyrejeyurtkeaufs", "yyuus"},
 58		iotype{"znm", "znm"},
 59		iotype{"nxaiqgj", "xqj"},
 60		iotype{"rsng", "sng"},
 61		iotype{"sxcpfwwyjsjfkrxpycnvcwvcnghwphpxrlfmcccvyppfr", "yyyr"},
 62		iotype{"ubvbsmbdayynthasljdikieqdjbnmr", "yytsr"},
 63		iotype{"dvypuukxnjiqwavhfsypfghhqhumbfznmjn", "znn"},
 64		iotype{"t", "t"},
 65		iotype{"lohyungouxtdkoqncecbecamiglwxamgkyjoisgymbeynmpftc", "yyyytc"},
 66		iotype{"mvcjkcbtzdyet", "zyt"},
 67		iotype{"zjejurusuqdatseyswqghs", "zyws"},
 68		iotype{"rkjqiepcwkgoobtawithjybepylvvwm", "yywm"},
 69		iotype{"sggqrxlcadkjjxcomhqgqpzkyetpz", "zz"},
 70		iotype{"oizojobmoeyncmosopractypj", "zyypj"},
 71		iotype{"qxydejwry", "yy"},
 72		iotype{"rnlrwcsgegebmwweybg", "yg"},
 73		iotype{"xbulkgnapqrb", "xurb"},
 74		iotype{"fqgq", "qq"},
 75		iotype{"euthsnsugfxtmfkwtlldwenybjfafvecasosvnxbs", "yxs"},
 76		iotype{"oxedpvevehtmfsletplcpnndvlxduxxwieibnthkhfnkpvhj", "xxxxwvj"},
 77		iotype{"akvccoziowkmrzpdwsvybiszfccgowzlosn", "zzzzsn"},
 78		iotype{"ixnaxxjgbmisqsjxjxgc", "xxxxxgc"},
 79		iotype{"i", "i"},
 80		iotype{"djouowzmqzafubqqenotqmwzfgcmtpveanvmb", "zzzvvmb"},
 81		iotype{"qparcaihdnyk", "yk"},
 82		iotype{"frraeazgnzdmhtbtaymysglanvdqlbmqicqw", "zzyyw"},
 83		iotype{"jeottiolzlxcy", "zy"},
 84		iotype{"gubnawecsnsekp", "wssp"},
 85		iotype{"uiktpzkdxynlifewoqmmbilpddlpecxndkebucbghbjqan", "zyxuqn"},
 86		iotype{"cjpxagblsqilexcqzjngqhnc", "zqnc"},
 87		iotype{"jvgloimmvsdhfgdafmzhxbzwfhkntrjpaocnidhfzeooqp", "zzzqp"},
 88		iotype{"mdvmgsxmxnvxgjtsheoxvmgoryhnkswbznzvfrdrqjm", "zzvrrqm"},
 89		iotype{"aanhrzdsbbhdoezohvuhzoeaekxpwhnj", "zzzxwnj"},
 90		iotype{"hhf", "hhf"},
 91		iotype{"onltutgmnnpxiwue", "xwue"},
 92		iotype{"ygng", "yng"},
 93		iotype{"sgrmksiyzesherusczthyotrbtzvegbzkulsprvikhohlyg", "zzzzyg"},
 94		iotype{"rgzoaitknjjioypjiaevejqldjgtw", "zyw"},
 95		iotype{"iynwupnztulzbyk", "zzyk"},
 96		iotype{"mrtnnhfvaqtctfuipndaye", "ye"},
 97		iotype{"zegbcvvxxfqxo", "zxxxo"},
 98		iotype{"kwpxplhnattmiuhdq", "xuq"},
 99		iotype{"zkhpjjfztbnxs", "zzxs"},
100		iotype{"wdxxiqzyhhxsp", "zyxsp"},
101		iotype{"egdnuvamuhkucdfvssxavdjuymvzgfymr", "zyr"},
102		iotype{"kwjuffpavnbkypmtfuxvabwj", "yxwj"},
103		iotype{"jbxoquxgeettykaciacheofaqceidc", "yqidc"},
104		iotype{"pnmqqmkogrhghpqwcpzdspbtvlvpotgdikgm", "zvvtm"},
105		iotype{"vwqmytncvpxazwrjwroacwono", "zwwwoo"},
106		iotype{"oehulzriqbdtawyytjskhlemqmdshspq", "zyytsssq"},
107		iotype{"mlwlasmlxqriipmqglsvswhnxyirhaofgyhkiwpo", "yywpo"},
108		iotype{"eszpgnfapcsbftxagmmdcqi", "zxqi"},
109		iotype{"rbjopthedsdewdudlupyicpmdtpmqrf", "ytrf"},
110		iotype{"renwjvqjfdzywfxpajvemksbdb", "zyxvsdb"},
111		iotype{"hnrthrdkyalotlymzcumobmvzvstciqmnbxdlgftjgpfbm", "zzxtpm"},
112		iotype{"uzkbkzmdozxqmvvmbbioyljyemntpldykxwjgnllqrdugrahe", "zzzyyyxwurhe"},
113		iotype{"tfhsnjkvbndnnqjkwfd", "wfd"},
114		iotype{"iy", "y"},
115		iotype{"zyeqfuqghbnhhrboymupudbomtlql", "zyyuutql"},
116		iotype{"yougpkmhhdmkorkkincpcnhxunainwqhbmmxkhwfarlahdmoak", "yxxwrok"},
117		iotype{"ljmlijlnlfaaynvqyhtxck", "yyxk"},
118		iotype{"ezhidvylyuyqluoxozyv", "zzyv"},
119		iotype{"kjqhcdshyfeqiwrencjowhqksyqeyeutemfgmyxs", "yyyyxs"},
120		iotype{"ydikqgggygevjdeyxpnzvmdvfkxralhnuvywensvwe", "zywwe"},
121		iotype{"rdpwejzcdxxcimwm", "zxxwm"},
122		iotype{"jtlgzwjtyaewnvgezxcyntlj", "zzytlj"},
123		iotype{"hjypqtcafblpnlxeaavswvaijkflyrekr", "yyrr"},
124		iotype{"drmtfhglfcmsobeqibtjcskngttvmzzpgkvxwctv", "zzxwv"},
125		iotype{"wvttsspponkjjihfebaa", "wvttsspponkjjihfebaa"},
126		iotype{"xwssrplkihgfc", "xwssrplkihgfc"},
127		iotype{"zzzyyyxwwvtronnlllljiiigeddccbbaa", "zzzyyyxwwvtronnlllljiiigeddccbbaa"},
128		iotype{"l", "l"},
129		iotype{"zxrrmfda", "zxrrmfda"},
130		iotype{"xwwvvutttssqqpppoonnnmllkkkkjjjihhffccccbbbba", "xwwvvutttssqqpppoonnnmllkkkkjjjihhffccccbbbba"},
131		iotype{"zyxuuuttttssqpoommmlkkjihgeeddccaaa", "zyxuuuttttssqpoommmlkkjihgeeddccaaa"},
132		iotype{"yxwsssrllkc", "yxwsssrllkc"},
133		iotype{"yvqqoollkca", "yvqqoollkca"},
134		iotype{"zyutttsqqppponnnnnmlllkkkjihhhggeeeddccbbb", "zyutttsqqppponnnnnmlllkkkjihhhggeeeddccbbb"},
135		iotype{"zxxvsrponmmljiiihgba", "zxxvsrponmmljiiihgba"},
136		iotype{"xwvssqoljjjiiigfccbaa", "xwvssqoljjjiiigfccbaa"},
137		iotype{"zzywwutsssrrronmllljjiihhgggggfeeea", "zzywwutsssrrronmllljjiihhgggggfeeea"},
138		iotype{"wvsqonkifecb", "wvsqonkifecb"},
139		iotype{"zzyyyxxwvvutssrrrqqppponmllkjjiihgffdcbbbaa", "zzyyyxxwvvutssrrrqqppponmllkjjiihgffdcbbbaa"},
140		iotype{"zzywuuusssrrrqponmlkkkiigfedccb", "zzywuuusssrrrqponmlkkkiigfedccb"},
141		iotype{"yyyyyyxxwwwvutttssrqqppppoonnmkjihgggddddaa", "yyyyyyxxwwwvutttssrqqppppoonnmkjihgggddddaa"},
142		iotype{"zxooc", "zxooc"},
143		iotype{"utqp", "utqp"},
144		iotype{"yxuttssrrnmjida", "yxuttssrrnmjida"},
145		iotype{"ffffeeeeeddddccccccccccbbbbbbbbaaa", "ffffeeeeeddddccccccccccbbbbbbbbaaa"},
146		iotype{"ffeeedcccca", "ffeeedcccca"},
147		iotype{"fdda", "fdda"},
148		iotype{"ffffeeeeeeddddcccccccbbbbbbbaaaaaaaaa", "ffffeeeeeeddddcccccccbbbbbbbaaaaaaaaa"},
149		iotype{"fffeeeeeddddddddcccccccbbbbbbbbbaaaa", "fffeeeeeddddddddcccccccbbbbbbbbbaaaa"},
150		iotype{"ffffeeeeeedddccccccbbbaaaa", "ffffeeeeeedddccccccbbbaaaa"},
151		iotype{"ffffffeeeeedddddddcccccccbbbbbbbbaaaaaaaa", "ffffffeeeeedddddddcccccccbbbbbbbbaaaaaaaa"},
152		iotype{"ddba", "ddba"},
153		iotype{"fffbbaaa", "fffbbaaa"},
154		iotype{"fedddccccbbbaa", "fedddccccbbbaa"},
155		iotype{"ffffeeeeeddbaaa", "ffffeeeeeddbaaa"},
156		iotype{"fffffeeeeeeeeeeedddddcccccccccccbbbbbbbbbbbaaaaa", "fffffeeeeeeeeeeedddddcccccccccccbbbbbbbbbbbaaaaa"},
157		iotype{"ffebbb", "ffebbb"},
158		iotype{"ffeedddcbbbbaa", "ffeedddcbbbbaa"},
159		iotype{"fffeeeeddccccbbbbbbbbaaaaaa", "fffeeeeddccccbbbbbbbbaaaaaa"},
160		iotype{"bbbb", "bbbb"},
161		iotype{"fffedaaaa", "fffedaaaa"},
162		iotype{"bbaaaabaabbaabbbaaabbaaabaaabababaaababaaaabbbbba", "bbbbbbbbbbbbbbbbbbbbba"},
163		iotype{"bbabbabbabaababaababaaaaaabaabab", "bbbbbbbbbbbbbb"},
164		iotype{"abbbbabbbbbbabbbbabbababbabbabbba", "bbbbbbbbbbbbbbbbbbbbbbbba"},
165		iotype{"bbbbbaabbaaabaabbababaabbababaabba", "bbbbbbbbbbbbbbbbbba"},
166		iotype{"bbbabababbaa", "bbbbbbbaa"},
167		iotype{"abbbbabbabbbabaaaaabaabaabaaababbbbabbb", "bbbbbbbbbbbbbbbbbbbbb"},
168		iotype{"babbaaaa", "bbbaaaa"},
169		iotype{"abbaabbaaaaabbbbbabbaaaaa", "bbbbbbbbbbbaaaaa"},
170		iotype{"baaababbaaabbbabbaaaaababaaabaaaaa", "bbbbbbbbbbbbaaaaa"},
171		iotype{"baabbaba", "bbbba"},
172		iotype{"aedcbacdeacdedbebbc", "eeeec"},
173		iotype{"caefdadbeedbebdcbcdca", "feeeddca"},
174		iotype{"fbbabcccbbbbfcabf", "fff"},
175		iotype{"ceaeedacaffddcfcdaebacdeeeb", "fffeeeeb"},
176		iotype{"dcbecaded", "eed"},
177		iotype{"ccddabecdfcbdefeedbbdaacda", "ffeeddda"},
178		iotype{"dcffbbbbcfefedbbbfcdafddebfcdfdeeccfe", "fffffffffe"},
179		iotype{"ffebcdbfccedbfaeaedaaaeefebdcdfa", "ffffffa"},
180		iotype{"addcfafeaeefcbefcbbcedfbcfcdffcaaeeafdadcfca", "ffffffffffca"},
181		iotype{"fcb", "fcb"},
182		iotype{"fgfdsdgaasfdghfgffggffgfgf", "sshgggggf"},
183		iotype{"asxcsa", "xsa"},
184		iotype{"fhjtgui", "ui"},
185		iotype{"naa", "naa"},
186		iotype{"ttt", "ttt"},
187		iotype{"maxbm", "xm"},
188		iotype{"baaaf", "f"},
189		iotype{"zba", "zba"},
190		iotype{"zzzzzzzzzzddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa", "zzzzzzzzzzddddddddddccccccccccbbbbbbbbbbaaaaaaaaaa"},
191		iotype{"hhhhhhh", "hhhhhhh"},
192		iotype{"tatttatttt", "tttttttt"},
193		iotype{"aaaaaaaaa", "aaaaaaaaa"},
194		iotype{"abcdefghgiabcdefghgiabcdefghgiabcdefghgiabcdefghgi", "iiiii"},
195		iotype{"zzzzz", "zzzzz"},
196		iotype{"aa", "aa"},
197		iotype{"bza", "za"},
198	}
199	for _, t := range tests {
200		a := getLargest(t.arg)
201		if a == t.result {
202			//fmt.Printf("OK\n")
203		} else {
204			fmt.Printf("NG return:%s expected:%s", a, t.result)
205		}
206	}
207}
208