HDU 2816 ( I Love You Too )

Problem : 2816 ( I Love You Too )     Judge Status : Accepted
RunId : 5794868    Language : C++    Author : ssun
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta

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

char st[12][6] = {"ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};
string change1 = "QWERTYUIOPASDFGHJKLZXCVBNM";
string change2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main()
{
    string str;
    char mob[1000];
    string mob1;
    string mob2;
    int i,j,k;
    int a,b;
    while(cin>>str)
    {
        for(i=0,j=0; i<str.size(); i=i+2,j++)
        {    
            a = str[i]-'0';
            b = str[i+1] - '0';
            mob[j] = st[a-2][b-1];
            for(k=0; k<change1.size(); k++)
                if(mob[j]==change1[k])
                {
                    mob[j] = change2[k];
                    break;
                }
    //        cout<<mob[j];
    //        cout<<a<<" "<<b<<endl;
        }
        mob[j]='\0';
        if(strlen(mob)%2==0)
        {
            mob1.assign(mob,0,(strlen(mob)/2));
            mob2.assign(mob,strlen(mob)/2,strlen(mob)/2);
        }
        else
        {
            mob1.assign(mob,0,(strlen(mob)/2+1));
            mob2.assign(mob,strlen(mob)/2+1,strlen(mob)/2);
        }
        
//        cout<<mob1<<endl<<mob2<<endl;
        for(i=0; i<strlen(mob); i=i+2)
        {
            mob[i] = mob1[i/2];
            mob[i+1] = mob2[i/2];
        }
        reverse(mob,mob+strlen(mob));
        string final(mob);        
        cout<<final<<endl;        
    }
    return 0;
}


你可能感兴趣的:(c,String)