hdu 字符串水题 hdu1073Online Judge 和 hdu1200To and Fro hdu1321Reverse Text

hdu1073Online Judge

#include <iostream>
using namespace std;

#define N    256
#define M    5010
char source[M];
char dist[M];
int  m_hash[N];

int main()
{
	int i, n, t;
	char tmpstr[N];
	while(scanf("%d", &t) != EOF)
	{
		while(t--)
		{
			getchar();
			memset(m_hash, 0, sizeof(m_hash));
			gets(source);
			while(gets(source) && strcmp(source, "END"))
			{
				n = strlen(source);
				if (!n)
				{
					++m_hash[(unsigned char)'\n'];
					continue;
				}
				for(i = 0;i < n;++i)
				{
					++m_hash[(unsigned char)source[i]];
				}
			}
			gets(source);
			while(gets(source) && strcmp(source, "END"))
			{
				n = strlen(source);
				if (!n)
				{
					--m_hash[(unsigned char)'\n'];
					continue;
				}
				for(i = 0;i < n;++i)
				{
					--m_hash[(unsigned char)source[i]];
				}
			}
			bool Presentation = false;
			for(i = 0;i < N; ++i)
			{

				if (m_hash[i] != 0)
				{
					if (i == (unsigned char)' ' || i == (unsigned char)'\t' || i == (unsigned char)'\n')
					{
						Presentation  = true;
						continue;
					}

					break;
				}
			}


			if (i == N)
			{
				if (Presentation  == false)
				{
					printf("Accepted\n");
				}
				else
				{
					printf("Presentation Error\n");
				}
			}
			else
			{
				printf("Wrong Answer\n");
			}

		}
	}
	return 0;
}


hdu1200To and Fro

#include <iostream>
using namespace std;

#define N  110
#define M  20

char m_hash[N][M];

int main()
{
	int c, r, i, j, flag, n;
	char str[2*N];
	while(scanf("%d", &c) != EOF && c)
	{
		scanf("%s", str);
		n = strlen(str);
		r = n / c;
		for (i = 0;i < r; ++i)
		{
			if (i %2 == 0)
			{
				for (j = 0; j < c; ++j)
				{
					m_hash[i][j] = str[i * c + j];
				}
			}
			else
			{
				for (j = c - 1; j >= 0; --j)
				{
					m_hash[i][c - j - 1] = str[i * c + j];
				}
			}
		}

		for (i = 0;i < c; ++i)
		{
			
			for (j = 0; j < r; ++j)
			{
					printf("%c", m_hash[j][i]);
			}
	
		}
		printf("\n");

	}
	return 0;
}

hdu1321Reverse Text

#include <iostream>
using namespace std;

#define N 100
char str[N];

void Reverse(char str[])
{
	int n = strlen(str), i, j;
	char tmp;

	for (i = 0, j = n - 1; i <= j ; ++i, --j)
	{
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
}


int main()
{
	int t;
	while(scanf("%d", &t) != EOF)
	{
		getchar();
		while(t--)
		{
			gets(str);
			Reverse(str);
			printf("%s\n", str);
		}

	}

	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值