POJ 3438 Look and Say

//============================================================================
// Name        : hello.cpp
// Author      : key
// Version     : ∞
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================



#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;


//POJ 3438

char str[1010];
int main()
{
    int temp;
    char *p;
    char pre;
    int t;
    scanf("%d",&t);
    while(t--&&scanf("%s",str)!=EOF)
    {
        pre = '0';
        p=str;
        temp = 0;
        while(1)
        {
            if(*p != pre)
            {
                if(temp!=0)
                    printf("%d%c",temp,pre);
                pre = *p;
                temp = 1;
            }
            else
                temp++;
            if(!(*p))
                break;
            p++;
        }
        printf("\n");
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章