#include <stdio.h>
#define MAX 100
typedef struct BALL{
int pois;
int direction;//Left:-1 Right:1
}Ball;
int main(){
int n,L,t,i,j,k,m;
Ball ball[MAX];
scanf("%d%d%d",&n,&L,&t);
for(i=0;i<n;i++){
scanf("%d",&ball[i].pois);
ball[i].direction=1;
//Endpoint change the direction
if(ball[i].pois==0||ball[i].pois==L)
ball[i].direction*=-1;
}
//The ball starts to move
for(i=0;i<t;i++){
for(j=0;j<n;j++){
ball[j].pois+=ball[j].direction;
if(ball[j].pois==0||ball[j].pois==L)
ball[j].direction*=-1;
}
//Collide
for(k=0;k<n;k++){
for(m=k+1;m<n;m++){
if(ball[m].pois==ball[k].pois){
ball[m].direction*=-1;
ball[k].direction*=-1;
}
}
}
}
for(i=0;i<n;i++)
printf("%d ",ball[i].pois);
return 0;
}
CCF-碰撞的小球(201803-2)-C语言(100分)
最新推荐文章于 2023-01-05 15:10:45 发布