HDU-2816 I Love You Too【字符串】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2816

题目大意:

给你一串数字,通过各种转换得到一个序列。。。。。

解题思路:

水题一道,但是自己代码能力太弱,处理字符串常常力不从心。。看来以后得全面开战,不能老刷一个专题了。。。改变一下。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
char num[9][4] = {{' ', ' ', ' ', ' '}, {'A', 'B', 'C', ' '},{'D', 'E', 'F', ' '},{'G', 'H', 'I', ' '},{'J', 'K', 'L', ' '},{'M', 'N', 'O',' '},{'P', 'Q', ' R', 'S'},{'T', 'U', 'V', ' '},{'W', 'X', 'Y', 'Z'}};
string a = "QWERTYUIOPASDFGHJKLZXCVBNM";
string b = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

char fun(char c)
{
    for(int i = 0; i < 52; ++i)
        if(a[i] == c)
            return b[i];
}

int main()
{
    char p[1010];
    string s, t, qian, hou, res;
    bool flag;
    int len, t1;
    while(~scanf("%s", p))
    {
        len = strlen(p);
        flag = true;
        s.clear(); t.clear(); qian.clear(); hou.clear(); res.clear();
        for(int i = 0; i < len; i += 2)
            s += num[(p[i] - '0') - 1][(p[i + 1] - '0') - 1];
        len = s.length();
        t1 = len;
        for(int i = 0; i < len; ++i)
            t += fun(s[i]);
        qian = t.substr(0, (len + 1) / 2);
        hou = t.substr((len + 1) / 2);
        len = qian.length();
        int len1 = hou.length();
        for(int i = 0, j = 0; i < len && j < len1; ++i, ++j)
        {
            res += qian[i];
            res += hou[j];
        }
        if(t1 % 2)
            res += qian[len - 1];
        for(int i = len + len1 - 1; i >= 0; --i)
            cout<<res[i];
        cout<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值