#include <iostream>
#include <string>
using namespace std;
string itos(int liczba){
char num[5];
itoa(liczba,num,10);
return num;
}
int main(){
int c;
string answer="";
cin>>c;
if(c>50){}
else{
for(unsigned int i = 0; i<c; ++i){
char w[200];
cin>>w;
string word(w);
string result;
char a_char;
int c=0;
for(unsigned int i = 0; i<word.length();++i){
a_char=word[i];
++c;
if(word[i]!=word[i+1]){
string u = word.substr(i-c+1,c);
unsigned int len=u.length();
u.erase(1,u.length()-1);
if(len>2)
u.append(itos(len));
result+=u;
c=0;
a_char=0;
}
}
answer+=result+'\n';
}
}
cout<<answer;
return 0;
}
Program działa w 100% pod Visulem, jednak na G++ pojawiają się problemy odnośnie:
prog.cpp: In function ‘std::string itos(int)’:
prog.cpp20: error: ‘itoa’ was not declared in this scope
prog.cpp: In function ‘int main()’:
prog.cpp29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
Dodam że jest to program ze SPOJ'a, Flamaster. Wiem że popełniam jeszcze dużo błędów, ale się uczę :)