#include <stdio.h>
#include <string.h>
int N;
int size; void main()
{
scanf("%d", &N);
getchar(); //读取残留的回车符
for(int i = ; i < N; i++)
{
int index = ;
char strIn[] = {'\0'};
char strOut[] = {'\0'};
int count['Z'] = {'\0'}; gets(strIn); //从键盘读取字符串
size = (int)strlen(strIn);
for(int j = ; j < size; j++)
{
if(strIn[j] >= 'A' && strIn[j] <= 'Z')
{
count[strIn[j]]++; //统计字母个数
}
else
return;
}
for(int i = 'A'; i < 'Z'; i++) //输出每个字母的个数
{
if(count[i] != ) //如果输入的字符串包含此字符
{
if(count[i] == )
{
strOut[index++] = i;
}
else
{
int len = ;
char str[] = {'/0'};
//strOut[index++] = count[i] + '0'; //统计相同字符个数
len = sprintf(str, "%d", count[i]);
strcat(&strOut[index], str);
index += len;
strOut[index++] = i;
}
}
}
printf("%s\n", strOut);
}
} HDU1020字符串操作-LMLPHP
#include <stdio.h>
#include <string.h>
int N;
int size; void main()
{
scanf("%d", &N);
getchar(); //读取残留的回车符
for(int i = ; i < N; i++)
{
char strIn[] = {'\0'}; gets(strIn); //从键盘读取字符串
size = (int)strlen(strIn);
for(int j = ; j < size;)
{
int k = ;
if(strIn[j] >= 'A' && strIn[j] <= 'Z')
{
char temp = '\0';
temp = strIn[j];
j++;
k = ;
while(strIn[j] == temp) //判断接下来是否有相同的字母
{
j++;
k++; //统计相同的字母个数
}
//输出个数和字母
if(k > )
printf("%d", k);
printf("%c",temp);
}
}
printf("\n");
}
}

HDU1020字符串操作-LMLPHP

 
HDU1020字符串操作-LMLPHP
HDU1020字符串操作-LMLPHP
05-11 21:53