Sicily 10572. SLOM

10572. SLOM

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Little Marin spent all his day generating test data for COCI. He simply couldn't make it work, so he had 

a nervous breakdown and can't even see clearly anymore. Every time he blinks while reading, the letters 

in a word get mixed up so that the letters from the second half of the word (the shorter half, if the 

length is an odd number) "jump in" between the letters from the first half in the following way:

 

? the last letter "jumps in" between the first and the second letter 

the penultimate letter "jumps in" between the second and the third letter 

the kth letter from the end "jumps in" between the kth and the (k+1)th letter from the beginning 

 

 

For example, the word "abcdef" would become "afbecd" after blinking. 

If Marin blinks again, the same thing happens. After two blinks, the word "abcdef" becomes "adfcbe". 

 

Marin has decided to write a program to help him determine what's exactly written on the screen. 

Unfortunately, after a day's work, he's simply too tired and he needs your help. You are given X, the 

number of blinks, and the word Marin sees on the screen. Write a program to solve the mystery for 

Marin and determine what was actually the word before he blinked X times. 

 

Input

The first line of input contains a positive integer X (1 ≤ ≤ 1 000 000 000), the number of times 

Marin blinked. 

The second line of input contains the word from the screen, its length being from the interval [3, 1000]. 

The word will consist only from small letters of English alphabet. 

 

Output

The first and only line of output must contain the original word, before Marin blinked X times. 
 

Sample Input

====Sample 1====
4 
acefdb
====Sample 2====
1000 
aaaaaa 
====Sample 3====
11 
srama

Sample Output

====Sample 1====
abcdef
====Sample 2====
aaaaaa 
====Sample 3====
sarma

Problem Source

2014年每周一赛第四场暨校赛模拟赛I/COCI

倒回去,遇到相同就记录,取模再进行

#include <stdio.h>
#include <string.h>

char a[1001], b[1001];
int length;
int half_length;
int counter;

void change() {
    char temp[1001];
    memset(temp, '\0', sizeof(temp));
    int i = 0;
    while (i < length) {
        temp[i / 2] = b[i];
        i++;
        if (i >= length)
            break;
        temp[length - i / 2 - 1] = b[i];
        i++;
    }
    strcpy(b, temp);
}

int main() {
    int n;
    scanf("%d", &n);
    memset(a, '\0', sizeof(a));
    memset(b, '\0', sizeof(b));
    scanf("%s", a);
    length = strlen(a);
    strcpy(b, a);
    change();
    counter = 1;
    while (strcmp(a, b)) {
        change();
        counter++;
    }
    n %= counter;
    while (n--) {
        change();
    }
    printf("%s\n", b);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值