Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_N 1000
- int v[MAX_N];
- int main()
- {
- FILE *fin,*fout;
- fin=fopen("portocal.in","r");
- fout=fopen("portocal.out","w");
- int n,k,p,poz,i,ck,j,cnt;
- fscanf(fin,"%d%d%d",&n,&k,&p);
- ///facem 1 simulare
- poz=0;
- for(i=0;i<n-1;i++){
- ck=k;
- while(ck>0){
- while(v[poz]==-1){
- poz=(poz+1)%n;
- }
- ck--;
- poz=(poz+1)%n;
- }
- poz=(poz+n-1)%n;
- v[poz]=-1;
- while(v[poz]==-1)
- poz=(poz+1)%n;
- }
- while(v[poz]==-1)
- poz=(poz+1)%n;
- cnt=1;
- while(poz!=p-1){
- poz=(poz+1)%n;
- cnt++;
- }
- fprintf(fout,"%d",cnt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement