• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Feb 17th, 2020 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. /*
2.
3. input: vetor de caracteres
4. retorna: o comprimento do vetor de caracteres comprimido
5. após a repetição de caracteres iguais, deve-se colocar apenas uma ocorrencia deste caractere, e sua quantidade
6.
7. 2
8.                           R
9. ["a","2","b","2","c","3","c"]
10.
11.             R
12. ["a", "3", "b", "b"]
13.                       x
14.
15. ["a", "b"]
16. ["a", "b"]
17.
18. ["a", "b", "b"]
19. ["a", "b", "b"]
20.
21.
22. */
23.
24. // input = 123
25. //
26. vector<char> intToCharVector(int input) {
27.   if (input == 0) {
30.   }
31.
32.     while (input > 0) {
33.     int lastDigit = input % 10; // 1
34.     char lastDigitChar = lastDigit + '0';
36.
37.     input /= 10;
38.   }
39.
42. }
43.
44.                              Ri
45. // ["a","2","b","2","c","3","c"]
46. int solve(vector<char> &input) {
47.   if (input.size() == 0) {
48.     return input.size();
49.   }
50.
51.   int currentCharCount = 0; // 3
52.   int writePointer = 0; // 0
53.
54.   for (int i = 0; i < input.size(); i++) {
55.     currentCharCount += 1;
56.
57.     if (i == input.size() - 1 || s[i] != s[i+1]) {
58.         input[writePointer] = currentChar;
59.       writePointer++;
60.
61.       if (currentCharCount > 1) {
62.         vector<char> digits = intToCharVector(currentCharCount);
63.         for (auto d : digits) {
64.           input[writePointer] = d;
65.           writePointer++;
66.         }
67.       }
68.
69.       currentCharCount = 0;
70.     }
71.   }
72.
73.   return writePointer;
74. }
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.
Top