杭电OJ 1020为什么错啊

Marvel_Z 2014-07-29 04:48:52
题目见这里http://acm.hdu.edu.cn/showproblem.php?pid=1020
我的代码编译已经通过
#include<stdio.h>
void main()
{
int line;
int str;
int count[26];
int character[26];
int i,j;
int find;
scanf("%d", &line);
getchar();
do
{
for (i = 0; i < 26; i++)
{
count[i] = 0;
character[i] = -1;
}
i = 0;
while ((str = getchar()) != '\n')
{
find = 0;
j = 0;
while (j<i)
{
if (character[j] == str)
{
find = 1;
break;
}
j++;
}

if (find == 1)
count[j]++;
else
{
character[i] = str;
count[i]++;
i++;
}
}
for (j = 0; j < i; j++)
{
if (count[j] == 1)
printf("%c", character[j]);
if (count[j]>1)
printf("%d%c", count[j], character[j]);
}
line--;
printf("\n");
} while (line);
}
...全文
277 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Falleyes 2014-07-29
  • 打赏
  • 举报
回复
引用 8 楼 zxh707wk 的回复:
引用 7 楼 Falleyes 的回复:
[quote=引用 6 楼 u012509810 的回复:] [quote=引用 5 楼 Falleyes 的回复:]
这题目好像在哪见过
ACM都很像的
707wk 2014-07-29
  • 打赏
  • 举报
回复
引用 7 楼 Falleyes 的回复:
[quote=引用 6 楼 u012509810 的回复:] [quote=引用 5 楼 Falleyes 的回复:] 这道题目的意思是要你把相同的字母序列变为数字加字母,比如AABAA,你应该输出2AB2A,而不是4AB。
按你说的我修改了代码通过了,话说题目里哪里说是这样的输出的呀?[/quote] 看这句: Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string. 每一个截取的字符串包含k个一样的字符,把他替换成kX,而这里X是这段截取字符串中唯一一种字符。 所以要求2A,就必须是AA,4A就一定是AAAA。[/quote]这题目好像在哪见过
Falleyes 2014-07-29
  • 打赏
  • 举报
回复
引用 6 楼 u012509810 的回复:
[quote=引用 5 楼 Falleyes 的回复:] 这道题目的意思是要你把相同的字母序列变为数字加字母,比如AABAA,你应该输出2AB2A,而不是4AB。
按你说的我修改了代码通过了,话说题目里哪里说是这样的输出的呀?[/quote] 看这句: Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string. 每一个截取的字符串包含k个一样的字符,把他替换成kX,而这里X是这段截取字符串中唯一一种字符。 所以要求2A,就必须是AA,4A就一定是AAAA。
Marvel_Z 2014-07-29
  • 打赏
  • 举报
回复
引用 5 楼 Falleyes 的回复:
这道题目的意思是要你把相同的字母序列变为数字加字母,比如AABAA,你应该输出2AB2A,而不是4AB。
按你说的我修改了代码通过了,话说题目里哪里说是这样的输出的呀?
Falleyes 2014-07-29
  • 打赏
  • 举报
回复
这道题目的意思是要你把相同的字母序列变为数字加字母,比如AABAA,你应该输出2AB2A,而不是4AB。
lx624909677 2014-07-29
  • 打赏
  • 举报
回复
引用 2 楼 lovesmiles 的回复:
 int find;
    scanf("%d", &line);
    getchar();
这里为什么还要getchar?
回收回车和空格
Falleyes 2014-07-29
  • 打赏
  • 举报
回复
这是我当年的代码:
#include<iostream>
#include<string>

using namespace std;

void main()
{
	int N;
	cin >> N;
	while (N--)
	{
		string str;
		cin >> str;

		char a = str[0];
		int num = 1;

		for (int i = 1; i<str.size(); i++)
		{
			if (str[i] == str[i - 1])    //打印该元素之前的字母
				num++;
			else
			{
				if (num == 1)
					cout << str[i - 1];
				else
					cout << num << str[i - 1];
				a = str[i];
				num = 1;
			}
			if (i == str.size() - 1)    //最后一个元素
			{
				if (num == 1)
					cout << str[i] << endl;
				else
					cout << num << str[i] << endl;
			}
		}
	}
	return;
}
勤奋的小游侠 2014-07-29
  • 打赏
  • 举报
回复
 int find;
    scanf("%d", &line);
    getchar();
这里为什么还要getchar?
lx624909677 2014-07-29
  • 打赏
  • 举报
回复
边界数据过不了或者其他数据过不去,编译通过只能说明你的代码在语法上没有错误,不代表在逻辑上也没有错误

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧