码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2041

时间:2015-06-10 18:42:24      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

 

POJ 2041

标签:

原文地址:http://www.cnblogs.com/gavinsp/p/4566636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!