69,373
社区成员
发帖
与我相关
我的任务
分享
#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);
}
[quote=引用 6 楼 u012509810 的回复:] [quote=引用 5 楼 Falleyes 的回复:] 这道题目的意思是要你把相同的字母序列变为数字加字母,比如AABAA,你应该输出2AB2A,而不是4AB。
[quote=引用 5 楼 Falleyes 的回复:] 这道题目的意思是要你把相同的字母序列变为数字加字母,比如AABAA,你应该输出2AB2A,而不是4AB。
这道题目的意思是要你把相同的字母序列变为数字加字母,比如AABAA,你应该输出2AB2A,而不是4AB。
这里为什么还要getchar?int find; scanf("%d", &line); getchar();
#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;
}
int find;
scanf("%d", &line);
getchar();
这里为什么还要getchar?