Advertisement
MonsterScripter

CodinGame_2023_08_25__23_35_19__char_int.cpp

Aug 25th, 2023
1,655
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 1 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. /**
  10.  *  Objectif
  11.  * Dans une chaîne S, remplacez chaque caractère (y compris les caractères non alphanumériques) par un entier représentant combien de fois il est apparu jusqu'à présent dans la chaîne. SENSIBLE À LA CASSE
  12.  *
  13.  * Entrée :
  14.  * Une chaîne S
  15.  *
  16.  * Sortie :
  17.  * Une chaîne de nombres représentant combien de fois chaque caractère (insensible à la casse) est apparu jusqu'à présent dans la chaîne.
  18.  *
  19.  * Contraintes :
  20.  * 0 < Longueur de S < 256
  21.  *
  22.  * Exemple :
  23.  * Entrée
  24.  * aAabBc
  25.  * Sortie
  26.  * 123121
  27.  */
  28.  
  29. int main()
  30. {
  31.     string s;
  32.     getline(cin, s);
  33.     int *arr = new int[256];
  34.     for (char c : s) {
  35.         char newC = std::tolower(c, std::locale());
  36.         arr[newC]++;
  37.         cout << arr[newC];
  38.     }
  39.     cout << endl;
  40.     delete[] arr; // Libère la mémoire allouée
  41.     exit(EXIT_SUCCESS);
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement