HDU 1982 Kaitou Kid - The Phantom Thief (1)

/*注意###--##类似的重复处理,同HDU 1062相似,直接使用2次串流可能会导致PE*/

#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

void process(string s)
{
    replace(s.begin(),s.end(),'-',' ');
    stringstream m(s);
    int t;
    while(m>>t)
    {
        cout<<(char)('A'+t-1);
    }
}

void run()
{
    string s,t="";
    cin>>s;

    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='#')
        {
            if(t!="")
            {
                process(t);
                t="";
            }
            cout<<" ";
        }
        else
        {
            t+=s[i];
        }
    }

    process(t);
    cout<<endl;
}

int main()
{
    int T;
    cin>>T;
    while(T--) run();
    return 0;
}

你可能感兴趣的:(Algorithm,ACM)