experiment 7-3-5 Output capital letters (15 branch )
This topic requires writing procedures , Output the uppercase English letters in the given string in sequence , Output each letter only once ; Output if there is no capital English letter “Not Found”.
Input format :
Enter as a string ending with carriage return ( Less than 80 Characters ).
Output format :
Output the uppercase English letters in one line according to the input order , Output each letter only once . Output if there is no capital English letter “Not Found”.
sample input 1:
FONTNAME and FILENAME
sample output 1:
FONTAMEIL
sample input 2:
fontname and filrname
sample output 2:
Not Found
#include<stdio.h> //2021/1/22 // Given the surge in reading of this blog Rewrite the solution // Easier to understand than the original
// If it's helpful to you, please give me a like int main (){ char str[100]; char ans[100]; // character string str Save input
ans Save the answer to output int i,j; gets(str); //gets Can read in the whole line Don't worry about being disturbed by spaces int p[100]={0};
//p The array verifies that uppercase letters have occurred once // subscript 0~25 corresponding A~Z for (i=0,j=0;str[i]!='\0';i++){
//gets The read string will be given to us '\0' ending So the condition is right and wrong '\0' Just do it char s=str[i]; if (s>='A'&&s<='Z') { int u=s
-'A'; // Through conversion u Becomes a subscript corresponding to a capital letter if (p[u]==0){ ans[j]=s; j++; // If the capital letter does not appear, then p[u]==0
join ans Final output p[u]++; // Because capital letters are output only once, so p[u] ++ I won't be able to judge next time I meet you } } } //j It has the function of counting
It can be judged at this time ans Is it empty if (j==0) printf ("Not Found"); else { for (i=0;i<j;i++) {
printf("%c",ans[i]); } } return 0; } // If it's helpful to you, please give me a like
Technology
Daily Recommendation