UVa 11541 Decoding

Code:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<vector>
using namespace std;
typedef pair<char,int> ci;
int main()
{
    int cas;
    cin>>cas;
    string line;
    getline(cin,line);
    for(int cc=1;cc<=cas;cc++)
    {
        vector<ci> v;
        string str;
        int n=0;
        char ch=' ';
        getline(cin,str);
        for(int i=0;i<str.size();i++)
        {
            if(i==0) ch=str[i];
            else
            {
                if(str[i]<='Z'&& str[i]>='A')
                {
                    v.push_back(ci(ch,n));
                    ch=str[i];
                    n=0;
                }
                else n=n*10+str[i]-'0';
            }
            if(i==str.size()-1) v.push_back(ci(ch,n));
        }
        printf("Case %d: ",cc);
        for(int i=0;i<v.size();i++)
        {
            ci tmp=v[i];
            for(int j=0;j<tmp.second;j++)
            {
                cout<<tmp.first;
            }
        }
        cout<<endl;
    }
    return 0;

}

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble