SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. void remove_element(int array[],int position,long int *n){
  4.     int i;
  5.     for(i=position;i<=(*n)-1;i++){
  6.         array[i]=array[i+1];
  7.     }
  8.     *n=*n-1;
  9. }
  10. int main(){
  11.     int k;
  12.     long int n;
  13.     scanf("%ld",&n);
  14.     scanf("%d",&k);
  15.     int *array=malloc(n*sizeof(int));
  16.     int i,j;
  17.     for(i=0;i<n;i++)
  18.         scanf("%d",&array[i]);
  19.     for(i=n-1;i>=0;i--){
  20.         int counter=0;
  21.         for(j=n-1;j>=0;j--){
  22.             if((i!=j)&&(array[i]+array[j])%k==0)
  23.             {
  24.                 remove_element(array,j,&n);
  25.                 j--;
  26.                 continue;
  27.             }
  28.             else if((i!=j)&&(array[i]+array[j])%k!=0){
  29.                 counter++;
  30.         }
  31.         }
  32.  
  33.         if(counter==n-1){
  34.             printf("%ld",n);
  35.             break;
  36.         }
  37.     }
  38.     return 0;
  39. }
  40.  
  41.  
  42. I only get about 4 test cases right from 20 test cases.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top