fork(1) download
  1. //by Carl Jalal
  2. #include <stdio.h>
  3.  
  4. int testCases;
  5. long int arraySize;
  6. int main()
  7. {
  8. scanf("%d",&testCases);
  9. while (testCases--){
  10. scanf("%ld",&arraySize);
  11. long int array[arraySize];
  12. for (long int i = 0; i < arraySize; i++){
  13. scanf("%ld",&array[i]);
  14. }
  15. for (long int i = 0; i < arraySize; i++){
  16. long int shift = 0;
  17. for (long int j = i+1; j < arraySize; j++){
  18. if (array[i] == array[j]) {
  19. shift++;
  20. }
  21. else array[j-shift] = array[j];
  22. }
  23. arraySize -= shift;
  24. }
  25.  
  26. printf("%ld",arraySize);
  27. }
  28. }
Success #stdin #stdout 0s 3344KB
stdin
5
9
1 1 1 1 1 1 1 1 1
9
1 2 3 4 5 6 7 8 9
9
9 8 7 6 5 4 3 2 1
9
1 2 3 1 2 3 1 2 3
9
3 2 1 3 2 1 3 2 1
stdout
19933