我是靠谱客的博主 整齐眼神,这篇文章主要介绍WOJ1157-Easy to Count输入格式输出格式样例输入样例输出,现在分享给大家,希望可以做个参考。

There are N boxes on one straight line which is long enough.
They move at the same speed, but their directions may be different. That is, some boxes
may move left, while the others move right. As a beautiful girl fond of algorithm and
programming, Alice finds that two boxes moving toward each other will collide, and
after collision their directions change while their speeds remain the same. Alice also
knows that the boxes will not collide any more after many times of collision, she names
this final status as the stable status. The task is to help her count the number of
collisions before reach the stable status.

输入格式

There are multiple test cases. For each test case, the first line is an integer N (1 <= N <= 10000) representing the number of boxes, and the second line is N integers,
separated by spaces. The i-th integer will be -1 if the i-th box move left, otherwise, it will be 1.
N = -1 indicates the end of input and should not be processed by your program.

输出格式

For each test case, output an integer which is the number of collisions to reach the
stable status on a single line in the format as indicated.

样例输入

复制代码
1
2
3
4
5
3 1 -1 1 4 1 -1 1 -1 -1

样例输出

复制代码
1
2
Case 1: 1 Case 2: 3

累加每个-1左边的1的个数,输出

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<stdio.h> int main(){ int n,i,a,ans,count,c=0; while(scanf("%d",&n)==1&&n!=-1){ c++; count=ans=0; for(i=0;i<n;i++){ scanf("%d",&a); if(a==1) count++; else if(a==-1) ans+=count; } printf("Case %d: %dn",c,ans); } return 0; }


最后

以上就是整齐眼神最近收集整理的关于WOJ1157-Easy to Count输入格式输出格式样例输入样例输出的全部内容,更多相关WOJ1157-Easy内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部