fjhcyu69

导航

 
**#include<stdio.h>
#include<string.h>

int main()
{
	char s[100];
	
	fgets(s, sizeof(s), stdin);
	char* p = s;

	int	Alphabet[26];
	for (int i = 0; i < 26; i++)
	{
		Alphabet[i] = 1;
	}

	int flag = 0;

	for (int i = 0; i < strlen(s); i++)
	{
		if (*p >= 'A' && *p <= 'Z')
		{
			if (Alphabet[*p - 'A'] == 1)
			{
				Alphabet[*p - 'A'] = 0;
				putchar(*p);
				flag = 1;
			}
		}
		p++;
	}
	if (!flag) {
		printf("Not Found");
	}

}

//我犯的错:
//1.应该用strlen来得到string的长度
//2.line21中忽视了AZ
//

这一个题将字符排序,用到了冒泡,其实和数组差不多,此外还有一个将替换字符串中的任一元素的操作

#include<stdio.h>
#include<string.h>

int main()
{
	char s[100];
	fgets(s, sizeof(s), stdin);

	s[strcspn(s, "\n")] = '\0';

	for (int i = 0; i < strlen(s)-1; i++)
	{
		for (int j = 0; j < strlen(s)-i-1; j++)
		{
			if (s[j] > s[j+1])
			{
				char temp = s[j + 1];
				s[j + 1] = s[j];
				s[j] = temp;
			}
		}
	}


	int index = 0; 
	for (int i = 0; i < strlen(s); i++)
	{
		if (s[i-1] != s[i])
		{
			s[index] = s[i];
			index++;
		}
	}
	s[index] = '\0';

	puts(s);
}**
posted on 2026-01-16 23:03  fjhcyu69  阅读(0)  评论(0)    收藏  举报