首页 > ACM题库 > HDU-杭电 > hdu 2265 Encoding The Diary[解题报告]C++
2014
01-04

hdu 2265 Encoding The Diary[解题报告]C++

Encoding The Diary

问题描述 :

You know many girls likes writing diaries,of course they have some secrets don’t want others to know.So this time, they asked you to encoding the diary.
The rule is :
Give you a string. Such as “ARE YOU AC?”
Firstly , delete all spaces in this string.
You will get “AREYOUAC?”
String AREYOUAC?
Index 123456789
Secondly,print the characters who’s index are the multiple of 3.
Thirdly, print the characters who’s index are the multiple of 2.If it has been printed,just ignore it .
At last,print the characters that have not been printed.

输入:

Each case will contain a string in one line.You may suppose the length of the string will not exceed 200.

输出:

Each case will contain a string in one line.You may suppose the length of the string will not exceed 200.

样例输入:

ARE YOU AC?

样例输出:

EU?RYCAOA

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
using namespace std;

int main()
{
    char str[500],s[500];
    int hash[500];
    int i,len,l;
    while(gets(s))
    {
        l = 1;
        len = strlen(s);
        memset(hash,0,sizeof(hash));
        for(i = 0;i<len;i++)
        {
            if(s[i]==' ')
            continue;
            str[l] = s[i];
            hash[l++] = 1;
        }
        for(i = 3;i<l;i+=3)
        {
            printf("%c",str[i]);
            hash[i] = 0;
        }
        for(i = 2;i<l;i+=2)
        {
            if(hash[i] == 0)
            continue;
            printf("%c",str[i]);
            hash[i] = 0;
        }
        for(i = 1;i<l;i++)
        {
            if(hash[i] == 0)
            continue;
            printf("%c",str[i]);
        }
        printf("\n");
    }

    return 0;
}

解题转自:http://blog.csdn.net/libin56842/article/details/14105019


  1. [email protected]