HDU 1020 - Encoding
Easy Problems -_-||
Input:
AABBBCDDDD
Output:
2A3BC4D
To practice more and simple example of input and output, not exactly algorithm, just practice. ..
*. -> Using string (char array) may be better.
#include<iostream>
#include<cstdio>
using namespace std;
void fRead(char cPrevious) {
char a;
int t = 1;
while(true) {
scanf("%c", &a);
if(cPrevious == a)
t++;
else
break;
}
if(t == 1)
cout << cPrevious;
else
cout << t << cPrevious;
if(a == '\n')
cout << endl;
else
fRead(a);
}
int main() {
int n;
char a;
scanf("%d", &n);
while(n--) {
scanf("%c", &a);
scanf("%c", &a);
fRead(a);
}
}