1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include <iostream> #include <algorithm> #include <queue> #include <vector> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <ctime> #include <iomanip> #include <cmath> #include <set> using namespace std; int main(int argc, char *argv[]) { int cnt; cin >> cnt; while (cnt--) { string str; cin >> str; string res; char curr = str[0]; int occ = 1; for (int i = 1;i < str.size();i++) { if(str[i] != curr){ if(occ == 1){ }else{ char tmp[5]; sprintf(tmp,"%d",occ); res += tmp; } res += curr; curr = str[i]; occ = 1; }else{ occ++; } } if(occ == 1){ }else{ char tmp[5]; sprintf(tmp,"%d",occ); res += tmp; } res += curr; cout << res << endl; } return 0; } |
非常非常非常水。连sprintf都放跑了。。。