24h購物| | PChome| 登入
2013-06-18 08:42:18| 人氣594| 回應0 | 上一篇 | 下一篇

[UVA] 11452 - Dancing the Cheeky-Cheeky

推薦 0 收藏 0 轉貼0 訂閱站台

 F. Dancing the Cheeky-Cheeky 

Context

The Cheeky-Cheeky is a new song. They dance it in Mula, and also in Hong Kong. All the freekies dance it, and the geek all love it. And the Cheeky-Cheeky is danced like this:

  1. The breikin-brokin.
  2. The meneito.
  3. The roboqueitor.
  4. The maiquel-guolkin.

The Problem

In this problem you have to learn to dance the Cheeky-Cheeky. This dancing consists of 4 basic steps (as listed above) that are arranged into a particular sequence. Then this sequence can be repeated an arbitrary number of times.

For example, if the sequence is "123", then the Cheeky-Cheeky is danced like this: "12312312312312...". But if the sequence is "123124", then the steps of the dancing are "123124123124123...".

You are given some of the steps of a particular dancing. Those steps will contain between 2 (inclusive) and 3 (not inclusive) times the basic sequence. You have to continue the dancing.

For example, if the basic sequence is "123", we can have the following possibilities:

Input

Output

123123 12312312...
1231231 23123123...
12312312 31231231...

The Input

The first line of the input contains an integer indicating the number of test cases.

Each case contains some of the first steps of a dancing. It is a single line with a list of digits (1, 2, 3 or 4) with no spaces between them. It will not have more than 2000 steps. Remember that the case contains the basic sequence twice, and possibly has some more steps (but not thrice).

The Output

For each test case, the output should contain the 8 following steps of the dancing, followed by three dots "...".

Sample Input

6
123123
1231231
12312312
123124123124
12312412312412
12312412312412312

Sample Output

12312312...
23123123...
31231231...
12312412...
31241231...
41231241...

題目會給 2 到 3 (不含) 的基礎節奏拍子。
然後告訴他接續 8 個拍子為何 ?

先想辦法窮舉出來基礎節奏的拍子為何。


#include <stdio.h>
#include <string.h>
char s[2005];
int main() {
int testcase;
scanf("%d", &testcase);
while(testcase--) {
scanf("%s", s);
int len = strlen(s);
int i, j;
for(i = len/2; i >= 0; i--) {
//basic[0 ... i], basic[i+1 ... i+i+1]
for(j = 0; j <= i; j++)
if(s[j] != s[i+j+1])
break;
if(j == i+1)
break;
}
int basicLen = i+1;
int pos = len-(i+i+2);
for(i = 0; i < 8; i++) {
putchar(s[pos]);
pos++;
if(pos >= basicLen) pos = 0;
}
puts("...");
}
return 0;
}
 

台長: Morris
人氣(594) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 10126 - Zipf's Law
此分類上一篇:[UVA] 257 - Palinwords

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文