Experiment 7-3-5 Output capital letters (15 points)

Experiment 7-3-5 Output capital letters (15 points)
This problem requires writing a program to sequentially output the uppercase English letters that have appeared in the given string, and output each letter only once; if there are no uppercase English letters, output "Not Found".

Input format:
Input is a carriage return terminated string (less than 80 characters).

Output format:
Output the uppercase English letters that have appeared in one line according to the order of input, and output each letter only once. If there are no uppercase English letters, "Not Found" is output.

Input sample 1:
FONTNAME and FILENAME

Sample output 1:
FONTAMEIL

Input sample 2:
fontname and filrname

Sample output 2:
Not Found

#include<stdio.h>
#include<string.h>
#define N 85
//Idea 1: store the input string; find all uppercase letters; remove all equal elements. This program uses: Idea 1
//Thinking 2: Define two arrays a[] b[] and compare the array elements in a[] with the array elements in b[] in turn, if a[] is a capital letter and
// If it is equal to the letter in b[], do not output, otherwise output the array element in a[].

int main(void)
{
	int i, j, temp, flag, len1=0, len2=0, cnt=0;
	char ch;
	char str1[N]; //Store the input string
	char str2[N]; //Store the processed string

	ch = getchar(); //input string
	for (i = 0; ch != '\n'; i++)
	{
		str1[i] = ch;
		len1++; //Record the length of the input string
		ch = getchar();
	}
	for (i = 0; i < len1; i++) //Preliminarily process the string to get a character array str2 containing uppercase letters
	{
		if (str1[i] >= 'A' && str1[i] <= 'Z')
		{
			str2[len2] = str1[i]; //Classic: store all uppercase letters. Set the counter, and add 1 to len2 only when a capital letter is found
			len2++; //Record the length of capital letters
		}
	}
	for (i = 0; i < len2; i++) //Double loop, detect equal elements in str2, and remove them
	{
		flag = 0; //update flag every time the loop starts
		for (j = 0; j < i; j++)
		{
			if (str2[i] == str2[j])
			{
				flag = 1;
			}
		}
		if (flag == 0)
		{
			printf("%c",str2[i]);
			cnt++;
		}
	}
	if (cnt == 0)
	{
		printf("Not Found");
	}

	return 0;
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326814774&siteId=291194637