Loading...
Submission
# When Author Problem Language CPU Memory
20838 2024-06-09 09:27:14 AHAMMED_99 Count Character C 0 ms 1516 kb Wrong Answer - 1
Test Cases
# CPU Memory Points
1 0 ms 1516 kb 0 Wrong Answer
2 0 ms 0 kb 0 Skipped
3 0 ms 0 kb 0 Skipped
4 0 ms 0 kb 0 Skipped
5 0 ms 0 kb 0 Skipped
6 0 ms 0 kb 0 Skipped
7 0 ms 0 kb 0 Skipped
8 0 ms 0 kb 0 Skipped
9 0 ms 0 kb 0 Skipped
Source Code
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void count_characters(char *s, int n, int *alice_count, int *bob_count) {
  5. // Initialize arrays to store counts
  6. memset(alice_count, 0, (n + 1) * sizeof(int));
  7. memset(bob_count, 0, (n + 1) * sizeof(int));
  8.  
  9. // Iterate through the string
  10. for (int i = 1; i <= n; i++) {
  11. // Update Alice's count
  12. alice_count[i] = alice_count[i - 1] + (strchr(s, s[i - 1]) == &s[i - 1]);
  13.  
  14. // Update Bob's count
  15. bob_count[i] = bob_count[i - 1] + 1;
  16. }
  17. }
  18.  
  19. int main() {
  20. int T;
  21. scanf("%d", &T);
  22.  
  23. for (int case_num = 1; case_num <= T; case_num++) {
  24. int N;
  25. scanf("%d", &N);
  26.  
  27. char S[N + 1];
  28. scanf("%s", S);
  29.  
  30. // Arrays to store counts for Alice and Bob
  31. int alice_count[N + 1], bob_count[N + 1];
  32.  
  33. // Calculate counts for Alice and Bob
  34. count_characters(S, N, alice_count, bob_count);
  35.  
  36. // Calculate total counts for Alice and Bob
  37. int total_alice_count = 0, total_bob_count = 0;
  38. for (int i = 0; i <= N; i++) {
  39. total_alice_count += alice_count[i];
  40. total_bob_count += bob_count[i];
  41. }
  42.  
  43. // Print the output for this test case
  44. printf("Case #%d: %d %d\n", case_num, total_alice_count, total_bob_count);
  45. }
  46.  
  47. return 0;
  48. }
  49.