1140 Look-and-say Sequence(20 分)

注意那个循环次数,是n-1不是n,坑死了,,,

#include
#include
#include
using namespace std;
int main()
{
    string s;
    int n, j;
    cin >> s >> n;
    n--;
    while (n--)
    {
        string temp;
        int i = 0, j = 0;
        while (i < s.length())
        {
            while (s[j] == s[i] && j < s.length())j++;
            temp += s[i] + to_string(j - i);
            i = j;
        }
        s = temp;
    }
    cout << s;
    return 0;
}

你可能感兴趣的:(1140 Look-and-say Sequence(20 分))