C语言程序在线求助
发布网友
发布时间:2022-05-27 13:22
我来回答
共3个回答
热心网友
时间:2023-10-25 04:46
#include<stdio.h>
#include<ctype.h>
int main()
{char a[100],ch;
int i,count[26],flag;
while(1)
{
printf("请输入一个字符串(a--z):\n");
scanf("%s",a);
for(i=0;i<26;i++)
count[i]=0;
flag=0;
for(i=0;a[i]!='\0';i++)
if(a[i]>='a'&&a[i]<='z')
count[a[i]-95]++;
for(i=0;i<26;i++)
if(count[i]==1)
{
printf("%c\n",i+95);
flag=1;
}
if(flag==0)
printf("no\n");
printf("是否继续输入字符串判断Y/N\n");
getchar();
if(ch=toupper(getchar())=='N')
break;
}
return 0;
}
热心网友
时间:2023-10-25 04:47
#include<stdio.h>
typedef struct CharCount
{
int count;
int first_position;
}CharCount;
void main()
{
int N = 0;
int i = 0;
int index = 0;
char buffer[1024];
CharCount count_list[26];
int first_occur_position = 0;
char first_occur_char = '\0';
scanf("%d", &N);
while (N--)
{
scanf("%s", buffer);
for (i = 0; i < 26; i++)
{
count_list[i].count = 0;
count_list[i].first_position = -1;
}
for (i = 0; '\0' != buffer[i]; i++)
{
index = buffer[i] - 'a';
if (0 == count_list[index].count)
{
count_list[index].first_position = i;
}
count_list[index].count++;
}
first_occur_char = '\0';
for (i = 0; i < 26; i++)
{
if (count_list[i].count != 1)
continue;
if ('\0' == first_occur_char)
{
first_occur_char = 'a' + i;
first_occur_position = count_list[i].first_position;
continue;
}
if (first_occur_position > count_list[i].first_position)
{
first_occur_char = 'a' + i;
first_occur_position = count_list[i].first_position;
}
}
if ('\0' == first_occur_char)
{
printf("no\n");
}
else
{
printf("%c\n", first_occur_char);
}
}
}
热心网友
时间:2023-10-25 04:47
#include <stdio.h>
int sh[50][26];
int main()
{
char s[50][200],*t,n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",s[i]);
for(t=s[i];*t;t++)
sh[i][*t-'a']++;
}
putchar(10);
for(i=0;i<n;i++)
{
for(t=s[i];*t;t++)
if(sh[i][*t-'a']==1) break;
if(*t)putchar(*t);
else printf("no");
putchar(10);
}
return 0;
}