fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int N;
  5. scanf("%d", &N);
  6.  
  7. int transaction;
  8.  
  9. int withdrawal_count = 0;
  10.  
  11. // Iterate through the transactions
  12. for (int i = 0; i < N; i++) {
  13. scanf("%d", &transaction);
  14.  
  15. // If it's a withdrawal (negative amount), print it
  16. if (transaction < 0) {
  17. if (withdrawal_count > 0) {
  18. printf(" ");
  19. }
  20. printf("%d", transaction);
  21. withdrawal_count++;
  22. }
  23. }
  24.  
  25. // Iterate through the transactions again to print deposits
  26. for (int i = 0; i < N; i++) {
  27. scanf("%d", &transaction);
  28.  
  29. // If it's a deposit (positive amount), print it
  30. if (transaction >= 0) {
  31. printf(" %d", transaction);
  32. }
  33. }
  34.  
  35. return 0;
  36. }
  37.  
  38.  
Success #stdin #stdout 0s 5308KB
stdin
5
12 -3 -22 98 
stdout
-3 -22 98 98 98 98 98