HDU--2265(Encoding The Diary)

Encoding The Diary

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


Problem Description
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.
 

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

Output
For each case, output the encoded string in one line.
 

Sample Input
 
 
ARE YOU AC?
 

Sample Output
 
 
EU?RYCAOA
 

这题是字符串的基础题,主要是需要先处理空格然后进行按索引输出,对于这题的话可以选择对于该字符串进行删空格处理,但是这样子的话会让时间复杂度过高,所以我利用一个flag来储存除去空格之后的字符索引位置,然后开两个辅助数组进行储存索引为2的倍数且不为3的倍数以及其他索引的字符,这样子利用空间换取时间减少时间复杂度。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
	char str[210];
	char a[210];
	char b[210];
	int temp1, temp2;
	while (gets(str))
	{
		int len = strlen(str);
		int flag = 0;
		temp1 = temp2 = 0;
		for (int i = 0; i < len; i++)
		{
			if (str[i] != ' ')
				flag++;
			else
				continue;
			if (flag % 3 == 0)
				printf("%c", str[i]);
			else if (flag % 2 == 0 && flag % 3 != 0)
				a[temp1++] = str[i];
			else if (flag % 3 != 0 && flag % 2 != 0)
				b[temp2++] = str[i];
		}
		a[temp1] = '\0';
		b[temp2] = '\0';
		printf("%s", a);
		printf("%s\n", b);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值