美文网首页
Codeforces #1005A.Tanya and Stai

Codeforces #1005A.Tanya and Stai

作者: 善法 | 来源:发表于2018-07-13 22:52 被阅读0次

原题链接:https://codeforces.com/contest/1005/problem/A

Tanya and Stairways

time limit per test:1 second memory limit per test:256 megabytes
input:standard input output:standard output

Description

Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 1 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 3 steps, and the second contains 4 steps, she will pronounce the numbers 1,2,3,1,2,3,4

小女孩谭雅在一个多层建筑内爬楼梯。每次她爬一层楼梯,她就会从1开始大声的数数,一直数到她现在楼层楼梯的阶数。例如,如果她爬两层楼梯,第一层楼梯3阶,第二层楼梯4阶,她就会数1,2,3,1,2,3,4

You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.

The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.

Input

The first line contains n (1≤n≤1000) — the total number of numbers pronounced by Tanya.

The second line contains integers a_1,a_2,…,a_n (1≤a_i≤1000) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with x steps, she will pronounce the numbers 1,2,…,x in that order.

The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.

Output

In the first line, output t — the number of stairways that Tanya climbed. In the second line, output t numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.

Examples

input
7
1 2 3 1 2 3 4
output
2
3 4 
input
4
1 1 1 1
output
4
1 1 1 1 
input
5
1 2 3 4 5
output
1
5 
input
5
1 2 1 2 1
output
3
2 2 1 

题目分析:根据输入,求出tanya爬了几层楼梯,并且分别是那几层楼梯。

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,x[1000],prev,curr,t; 
    //x数组存放阶梯,prev、curr分别存放上一次和这一次所在的阶梯
    t=0;prev=0; // 初始化
    scanf("%d",&n);
    while (n--)
    {
        scanf("%d",&curr);
        if (curr<=prev)
        {
            x[t++] = prev;
            prev = 1;
        }
        prev = curr;
    }
    x[t++] = prev;
    printf("%d\n",t);
    for (int i=0; i<t; i++)
        printf("%d ",x[i]);
    return 0;
}

相关文章

网友评论

      本文标题:Codeforces #1005A.Tanya and Stai

      本文链接:https://www.haomeiwen.com/subject/unnspftx.html