10 分間コーディングで 30 分かかった・・・
C#と諸々 10分でコーディング
10分でコーディング|プログラミングに自信があるやつこい!!
乗り遅れた感はあるけど、SQL でやってみた。
WITH Input(id, numPlayers, deck) AS ( SELECT 1, 3, '123123123' UNION ALL SELECT 2, 4, '123123123' UNION ALL SELECT 3, 6, '012345012345012345' UNION ALL SELECT 4, 4, '111122223333' UNION ALL SELECT 5, 1, '012345012345012345' UNION ALL SELECT 6, 6, '01234' UNION ALL SELECT 7, 2, '' UNION ALL SELECT 8, 0, '' UNION ALL SELECT 9, 0, '123' ) , Cards(id, i, card, deck) AS ( SELECT id , 0 , LEFT(deck, 1) , SUBSTRING(deck, 2, LEN(deck)) FROM Input WHERE deck <> '' UNION ALL SELECT id , i + 1 , LEFT(deck, 1) , SUBSTRING(deck, 2, LEN(deck)) FROM Cards WHERE deck <> '' ) , Players(id, player, n, total) AS ( SELECT id , 1 , numPlayers , numPlayers FROM Input WHERE numPlayers <> 0 UNION ALL SELECT id , player + 1 , n - 1 , total FROM Players WHERE n <> 1 ) , DealSrc(id, i, player, card, total) AS ( SELECT Player.id , COALESCE(Card.i + 1, Player.player) , Player.player , COALESCE(Card.card, '') , Player.total FROM Players Player LEFT OUTER JOIN Cards Card ON Player.id = Card.id AND Player.player = (Card.i % Player.total + 1) ) , Concated(id, i, player, cards) AS ( SELECT id , i , player , CAST(card AS varchar(max)) FROM DealSrc WHERE i = 1 UNION ALL SELECT Concated.id , Concated.i + Src.total , Concated.player , Concated.cards + Src.card FROM Concated INNER JOIN DealSrc Src ON Concated.id = Src.id AND Concated.player = Src.player WHERE Concated.i + Src.total = Src.i ) , Deal_(id, player, cards) AS ( SELECT id , player , cards FROM Concated P WHERE LEN(cards) = (SELECT MAX(LEN(cards)) FROM Concated C WHERE P.id = C.id AND P.player = C.player) ) , Deal(id, player, cards) AS ( SELECT id , player , LEFT(cards, (SELECT MIN(LEN(cards)) FROM Deal_ C WHERE P.id = C.id)) FROM Deal_ P ) SELECT * FROM Deal ORDER BY id, player
あまりに簡単なので制限時間を10分としてやってみてください。
10分でコーディング|プログラミングに自信があるやつこい!!
これ以上かかった人は
自分はかなりプログラミングができない。
とつらい事実を認識しましょう。
がーん。精進します!
追記:
結果張り忘れてたw
id | player | cards |
---|---|---|
1 | 1 | 111 |
1 | 2 | 222 |
1 | 3 | 333 |
2 | 1 | 12 |
2 | 2 | 23 |
2 | 3 | 31 |
2 | 4 | 12 |
3 | 1 | 000 |
3 | 2 | 111 |
3 | 3 | 222 |
3 | 4 | 333 |
3 | 5 | 444 |
3 | 6 | 555 |
4 | 1 | 123 |
4 | 2 | 123 |
4 | 3 | 123 |
4 | 4 | 123 |
5 | 1 | 012345012345012345 |
6 | 1 | |
6 | 2 | |
6 | 3 | |
6 | 4 | |
6 | 5 | |
6 | 6 | |
7 | 1 | |
7 | 2 |