markdown 在线制作ppt json校验和格式化工具

POJ 1051

#include <iostream>
#include <algorithm>
#include <string>
#define MAXN 27
using namespace std;

struct node
{
    int len;
    string s;
};
char fun(string s);
node _node[MAXN];
int n[100];

int main()
{
    int time = 0;
    //freopen("acm.acm","r",stdin);
    int i;
    _node[0].len = 2;
    _node[0].s = ".-";
    _node[1].len = 4;
    _node[1].s = "-...";
    _node[2].len = 4;
    _node[2].s = "-.-.";
    _node[3].len = 3;
    _node[3].s = "-..";
    _node[4].len = 1;
    _node[4].s = ".";
    _node[5].len = 4;
    _node[5].s = "..-.";
    _node[6].len = 3;
    _node[6].s = "--.";

    _node[7].len = 4;
    _node[7].s = "....";
    _node[8].len = 2;
    _node[8].s = "..";
    _node[9].len = 4;
    _node[9].s = ".---";
    _node[10].len = 3;
    _node[10].s = "-.-";
    _node[11].len = 4;
    _node[11].s = ".-..";
    _node[12].len = 2;
    _node[12].s = "--";
    _node[13].len = 2;
    _node[13].s = "-.";

    _node[14].len = 3;
    _node[14].s = "---";
    _node[15].len = 4;
    _node[15].s = ".--.";
    _node[16].len = 4;
    _node[16].s = "--.-";
    _node[17].len = 3;
    _node[17].s = ".-.";
    _node[18].len = 3;
    _node[18].s = "...";
    _node[19].len = 1;
    _node[19].s = "-";
    _node[20].len = 3;
    _node[20].s = "..-";
    _node[21].len = 4;
    _node[21].s = "...-";
    _node[22].len = 3;
    _node[22].s = ".--";
    _node[23].len = 4;
    _node[23].s = "-..-";
    _node[24].len = 4;
    _node[24].s = "-.--";
    _node[25].len = 4;
    _node[25].s = "--..";

    int test;
    string _s;
    string s;
//    int i;
    cin>>test;
    while(test --)
    {

        cin>>s;
        _s = "";
        for(i = 0; i < s.length(); ++ i)
        {
            if(s[i] >= 'A' && s[i] <= 'Z')
            {
                _s += _node[s[i]-'A'].s;
                n[i] = _node[s[i]-'A'].len;
            }
            else if(s[i] == '_')
            {
                _s += "..--";
                n[i] = 4;
            }
            else if(s[i] ==',')
            {
                _s += ".-.-";
                n[i] = 4;
            }
            else if(s[i] == '.')
            {
                _s += "---.";
                n[i] = 4;
            }
            else if(s[i] == '?')
            {
                _s += "----";
                n[i] = 4;
            }
        }
        reverse(n,n+s.length());
    //    for(i = 0; i < s.length(); ++ i)
    //    {    
    //        cout<<n[i]<<" ";
    //    }
    //    cout<<s<<endl;
    //    cout<<_s<<endl;
    //    cout<<endl;
        cout<<++ time<<": ";
        int j = 0;
        for(i = 0; i < _s.length();)
        {
            string k;
            k = _s.substr(i,n[j]);
            i += n[j ++];
            //cout<<k<<endl;
            //    cout<<(char)(fun(k)+'A');
        //    cout<<k<<" ";
            cout<<fun(k);
        }
        cout<<endl;
    }
}

char fun(string s)
{
    int i;
    if(s == "..--")
    {
        return '_';
    }
    else if(s == ".-.-")
    {
        return ',';
    }
    else if(s == "---.")
    {
        return '.';
    }
    else if(s == "----")
    {
        return '?';
    }

    for(i = 0; i < MAXN; ++ i)
    {
        if(_node[i].s == s)
        {
            return char('A'+i);
        }
    }
}

 

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

技术网站地址: vmfor.com

posted @ 2015-06-09 13:25  GavinHacker  阅读(151)  评论(0编辑  收藏  举报
markdown 在线制作ppt json校验和格式化工具