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

POJ 2041

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

string fun_c(string s);
string fun_j(string s);
string fun_e(string s);
string fun_a(string s);
string fun_p(string s);
string fun_m(string s);


int main()
{
    //freopen("acm.acm","r",stdin);
    int n;
    string op;
    string s; 
    int i;
    cin>>n;
    while(n --)
    {
        cin>>op;
        cin>>s;
        //cout<<op<<endl;
        for(i = op.length()-1; i >= 0; -- i)
        {
            if(op[i] == 'A')
            {
                s = fun_a(s);
            }
            else if(op[i] == 'C')
            {
                s = fun_c(s);
            }
            else if(op[i] == 'J')
            {
                s = fun_j(s);
            }
            else if(op[i] == 'M')
            {
                s = fun_m(s);
            }
            else if(op[i] == 'P')
            {
                s = fun_p(s);
            }
            else if(op[i] == 'E')
            {
                s = fun_e(s);
            }

        }
        cout<<s<<endl;
    }
}

string fun_j(string s)
{
    char tem;
    int i;
//    cout<<" 000000 "<<s.length()<<endl;
    tem = s[s.length()-1];
    for(i = s.length()-1; i > 0; -- i)
    {
        s[i] = s[i-1];
    }
    s[0] = tem;
    return s;
}

string fun_c(string s)
{
    int i;
    char tem;
    tem = s[0];
    for(i = 0; i < s.length()-1; ++ i)
    {
        s[i] = s[i+1];
    }
    s[s.length()-1] = tem;
    return s;
}

string fun_e(string s)
{
//    cout<<"s :"<<s<<endl;
    int len_half;
    len_half = s.length()/2;
    string s_pre;
    string s_bac;
    int len_half_1;
    int i;
//    cout<<s.length()<<endl;
//    cout<<"len "<<endl;
    for(i = 0; i < len_half; ++ i)
    {
        s_pre += s[i];
    }
    len_half_1 = s.length()-len_half;
    for(i = len_half_1;  i < s.length(); ++ i)
    {
        s_bac += s[i];
    }

    for(i = 0; i < len_half; ++ i)
    {
        s[i] = s_bac[i];
    }
//    cout<<len_half<<endl;
//    cout<<len_half_1<<endl;
//    cout<<")))))))))))))))"<<endl;
    int j = 0;
    for(i = len_half_1; i < s.length(); ++ i)
    {
        s[i] = s_pre[j ++];
    }
    
//    cout<<"p :"<<s_pre<<endl;
//    cout<<"b :"<<s_bac<<endl;
    return s;
}

string fun_a(string s)
{
    reverse(s.begin(),s.end());
    return s;
}

string fun_p(string s)
{
    int i;
    for(i = 0; i < s.length(); ++ i)
    {
        if(s[i] >= '1' && s[i] <= '9')
        {
            s[i] = char(s[i]-1);
        }
        else if(s[i] == '0')
        {
            s[i] = '9';
        }
    }
    return s;
}


string fun_m(string s)
{
    int i;
    for(i = 0; i < s.length(); ++ i)
    {
        if(s[i] >= '0' && s[i] <= '8')
        {
            s[i] = char(s[i]+1);
        }
        else if(s[i] == '9')
        {
            s[i] = '0';
        }
    }
    return s;
}

 

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

技术网站地址: vmfor.com

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