Summiya14Fis14Samaa

URI marbles

Jul 25th, 2020
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include<stdio.h>
  2. void Do_Ureally_want_to(int arr[], int size);
  3. int main(){
  4.     //freopen("input.txt","rt",stdin);
  5.     //freopen("output.txt","wt",stdout);
  6.     int marbles_n, queries,i,j,k__=1;
  7.    
  8.     scanf("%d%d",&marbles_n,&queries);
  9.    
  10.     do{
  11.         int marblos[marbles_n], query[queries];
  12.        
  13.         for(i=0; i<marbles_n; i++)
  14.             scanf("%d",&marblos[i]);
  15.         Do_Ureally_want_to(marblos, marbles_n);
  16.         for(i=0; i<queries; i++)
  17.             scanf("%d",&query[i]);
  18.                                
  19.         for(i=0; i<queries; i++){
  20.             for(j=0; j<marbles_n; j++){
  21.                  
  22.                 if(query[i]==marblos[j])
  23.                 {
  24.                    
  25.                     i==0? (printf("CASE# %d:\n",k__))+(k__++):0;
  26.                    
  27.                     printf("%d found at %d\n",query[i],(j+1));  break;
  28.                 }
  29.                
  30.                 else if((j+1) == marbles_n){
  31.                    
  32.                     i==0? (printf("CASE# %d:\n",k__))+(k__++):0;
  33.                    
  34.                     printf("%d not found\n",query[i]);  break;
  35.                 }
  36.             }
  37.         }
  38.            
  39.         scanf("%d%d",&marbles_n,&queries); 
  40.     }while(queries!=0 && marbles_n!=0);
  41. }
  42.  
  43. void Do_Ureally_want_to(int arr[], int size){
  44.     int i,j,key;
  45.    
  46.     for(i=0; i<size; i++){
  47.         key = arr[i];
  48.         j = i-1;
  49.         /*Move elements of arr[0..i-1], that are greater than key,
  50.         to one position to the right.*/
  51.         while(j>=0 && arr[j]>key){
  52.            
  53.             arr[j+1] = arr[j];
  54.             j--;
  55.         }
  56.         arr[j+1] = key;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment