Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- void stringDecompress(char* result, const char* str)
- {
- char numstr[] = "0";
- strcpy(result, "");
- int i = 0;
- while (*(str + i))
- {
- if (isdigit(str[i]))
- {
- strncat(numstr, &str[i], 1);
- }
- else
- {
- int cnt = atoi(numstr);
- for (int j = 0; j < cnt; j++)
- {
- strncat(result, &str[i], 1);
- }
- strcpy(numstr, "0");
- }
- i++;
- }
- }
- int main()
- {
- char *str;
- stringDecompress(str, "3A2B4C");
- int i = 0;
- while (*(str + i))
- {
- cout << str[i];
- i++;
- }
- cout << endl;
- stringDecompress(str, "12W1B12W3B24W1B14W");
- i = 0;
- while (*(str + i))
- {
- cout << str[i];
- i++;
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement