POJ 2013 Symmetric Order(내 수제의 길 - 짝짓기 출력)

Symmetric Order
Time Limit: 1000MS
 
Memory Limit: 30000K
Total Submissions: 9787
 
Accepted: 6033
Description
In your job at Albatross Circus Management (yes, it's run by a bunch of clowns), you have just finished writing a program whose output is a list of names in nondescending order by length (so that each name is at least as long as the one preceding it). However, your boss does not like the way the output looks, and instead wants the output to appear more symmetric, with the shorter strings at the top and bottom and the longer strings in the middle. His rule is that each pair of names belongs on opposite ends of the list, and the first name in the pair is always in the top part of the list. In the first example set below, Bo and Pat are the first pair, Jean and Kevin the second pair, etc. 
Input
The input consists of one or more sets of strings, followed by a final line containing only the value 0. Each set starts with a line containing an integer, n, which is the number of strings in the set, followed by n strings, one per line, sorted in nondescending order by length. None of the strings contain spaces. There is at least one and no more than 15 strings per set. Each string is at most 25 characters long.
Output
For each input set print "SET n"on a line, where n starts at 1, followed by the output set as shown in the sample output.
Sample Input
7
Bo
Pat
Jean
Kevin
Claude
William
Marybeth
6
Jim
Ben
Zoe
Joey
Frederick
Annabelle
5
John
Bill
Fran
Stan
Cece
0

Sample Output
SET 1
Bo
Jean
Claude
Marybeth
William
Kevin
Pat
SET 2
Jim
Zoe
Frederick
Annabelle
Joey
Ben
SET 3
John
Fran
Cece
Stan
Bill

Source
Mid-Central USA 2004
먼저 숫자 N을 주고, 그 다음에 N줄에서 N개의 문자열을 얻고, 먼저 홀수 줄을 출력하고, 그 다음에 짝수 줄을 출력하도록 요구한다.
직접 시뮬레이션, 홀수 줄은 하나의 단일 순환으로 최대로 출력되고, 그 다음에 짝수 줄은 N-1-N% 2줄에서 0줄로 점차 출력됩니다.
참고 사항:
1)
문자열 배열은 0부터 시작합니다.
N이 홀수이면 짝수 시작 동작 N-2;
     
N이 짝수이면 짝수 시작 동작 N-1;
즉 짝수 시작 비헤이비어 N-1-N%2입니다.
코드(1AC):
#include <cstdio>
#include <cstdlib>
#include <cstring>

char str[100][30];

int main(void){
    int casenum, ii;
    int N;
    int i;

    for (ii = 1; 1; ii++){
        memset(str, 0, sizeof(str));
        scanf("%d", &N);
        if (!N){
            break;
        }
        getchar();
        for (i = 0; i < N ; i ++){
            scanf("%s", str[i]);
        }
        printf("SET %d
", ii); for (i = 0; i < N; i += 2){ printf("%s
", str[i]); } for (i = N - 1 - N % 2; i >= 0 ; i -= 2){ printf("%s
", str[i]); } } return 0; }

좋은 웹페이지 즐겨찾기