hdoj 2816 I Love You Too

I Love You Too

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1756    Accepted Submission(s):
1056

Problem Description

This is a true story. A man showed his
love to a girl,but the girl didn‘t replied clearly ,just gave him a Morse
Code:
****-/*----/----*/****-/****-/*----/---**/*----/****-/*----/-****/***--/****-/*----/----*/**---/-****/**---/**---/***--/--***/****-/
  He was so anxious that he asked for help in the Internet and after one day a
girl named "Pianyi angel" found the secret of this code. She translate this code
as this five steps:
1.First translate the morse code to a number
string:4194418141634192622374
2.Second she cut two number as one group
41 94 41 81 41 63 41 92 62 23 74,according to standard Mobile phone can
get this alphabet:GZGTGOGXNCS

3.Third she change
this alphabet according to the keyboard:QWERTYUIOPASDFGHJKLZXCVBNM =
ABCDEFGHIJKLMNOPQRSTUVWXYZ

So ,we can get OTOEOIOUYVL
4.Fourth,
divide this alphabet to two parts: OTOEOI and OUYVL, compose
again.we will get OOTUOYEVOLI
5.Finally,reverse this alphabet the
answer will appear : I LOVE YOU TOO

I guess you might
worship Pianyi angel as me,so let‘s Orz her.
Now,the task is translate the
number strings.

Input

A number string each line(length <= 1000). I ensure
all input are legal.

Output

An upper alphabet string.

Sample Input

4194418141634192622374

41944181416341926223

Sample Output

ILOVEYOUTOO

VOYEUOOTIO

不断地模拟,根据题目翻译密码

#include<stdio.h>
#include<string.h>
#define MAX 1100
char s[MAX];
int a[30];
char str2[MAX];
char str5[MAX];
char str3[30]={"QWERTYUIOPASDFGHJKLZXCVBNM"};
char str4[30]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
char str1[20][5]={"\0","\0","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};
char str6[MAX],str7[MAX];
int main()
{
    int n,m,j,i,t,l1,l2,l3,l4;
    while(scanf("%s",s)!=EOF)
    {
        memset(a,0,sizeof(a));
        memset(str2,‘\0‘,sizeof(str2));
        memset(str5,‘\0‘,sizeof(str5));
        memset(str6,‘\0‘,sizeof(str6));
        memset(str7,‘\0‘,sizeof(str7));
        l1=strlen(s);
        j=0;
        for(i=0;i<l1;i=i+2,j++)
            str2[j]=str1[s[i]-‘0‘][s[i+1]-‘1‘];
        l2=strlen(str2);
        for(i=0;i<l2;i++)
        for(j=0;j<26;j++)
        {
            if(str2[i]==str3[j])
            {
                a[i]=j;
                break;
            }
        }
        for(i=0;i<l2;i++)
            str5[i]=str4[a[i]];
        int k=l2/2;
        j=0;
        if(l2&1)
        {
            for(i=l2-1;i>k;i--)
            str6[j++]=str5[i];
            j=0;
            for(i=k;i>=0;i--)
            str7[j++]=str5[i];
       }
       else
       {
       	    for(i=l2-1;i>=k;i--)
            str6[j++]=str5[i];
	        j=0;
            for(i=k-1;i>=0;i--)
            str7[j++]=str5[i];
       }
        if(l2&1)
        for(i=0;i<=k;i++)
        {
            printf("%c",str7[i]);
            if(i==k)
            break;
            printf("%c",str6[i]);
        }
        else
        for(i=0;i<k;i++)
        {
            printf("%c",str6[i]);
            printf("%c",str7[i]);
        }
        printf("\n");
    }
    return 0;
}

  

时间: 2025-01-31 18:38:27

hdoj 2816 I Love You Too的相关文章

HDOJ 题目分类

HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:    用STL中的next_permutation()1029:1032:1037:1039:1040:1056:1064:1065:1076:    闰年 1084:1085:1089,1090,1091,1092,1093,1094, 1095, 1096:全是A+B1108:1157:1196:1

【HDOJ】4328 Cut the cake

将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. 1 /* 4328 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector>

POJ Xiangqi 4001 &amp;&amp; HDOJ 4121 Xiangqi

题目链接(POJ):http://poj.org/problem?id=4001 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=4121 Xiangqi Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1108   Accepted: 299 Description Xiangqi is one of the most popular two-player boa

【HDOJ】4956 Poor Hanamichi

基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. 1 #include <cstdio> 2 3 int f(__int64 x) { 4 int i, sum; 5 6 i = sum = 0; 7 while (x) { 8 if (i & 1) 9 sum -= x%10; 10 else 11 sum += x%10; 12 ++i; 13 x/=10; 14 } 15 return sum; 16 } 17 18 int main() { 1

HDOJ 4901 The Romantic Hero

DP....扫两遍组合起来 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 547    Accepted Submission(s): 217 Problem Description There is an old country and the king fell in love with a

【HDOJ】1099 Lottery

题意超难懂,实则一道概率论的题目.求P(n).P(n) = n*(1+1/2+1/3+1/4+...+1/n).结果如果可以除尽则表示为整数,否则表示为假分数. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 25 5 6 __int64 buf[MAXN]; 7 8 __int64 gcd(__int64 a, __int64 b) { 9 if (b == 0) return a; 10 else return

【HDOJ】2844 Coins

完全背包. 1 #include <stdio.h> 2 #include <string.h> 3 4 int a[105], c[105]; 5 int n, m; 6 int dp[100005]; 7 8 int mymax(int a, int b) { 9 return a>b ? a:b; 10 } 11 12 void CompletePack(int c) { 13 int i; 14 15 for (i=c; i<=m; ++i) 16 dp[i]

HDOJ 3790 双权值Dijkstra

1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <cstring> 5 using namespace std; 6 7 const int INF = 1000000; 8 const int MAXSIZE = 1005; 9 10 int map[MAXSIZE][MAXSIZE]; 11 int price[MAXSIZE][MAXSIZE]; 1

HDOJ 1217 Floyed Template

1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <cstring> 5 #include<map> 6 using namespace std; 7 8 map<string,int>name; 9 const int INF = 1000000; 10 const int MAXSIZE = 1005; 11 const int