PTA remove duplicate characters

7-10 Deleting Repeated Characters
This question requires writing a program. After removing the repeated characters from a given string, the output will be sorted according to the ASCII code of the characters from smallest to largest.

Input format: The
input is a non-empty string (less than 80 characters) ending with a carriage return.

Output format:
output the result string after reordering.

Input sample:

ad2f3adjfeainzzzv

Sample output:

23adefijnvz

This question was originally very simple, but I was confused by the comparison of ASCII codes for a while, but when I thought, isn't the computer's comparison of letters directly compared to its ASCII code? This is the reaction!
Problem-solving code

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

int main()
{
    
    
	char a[81];
	gets(a);
    //scanf("%s",a);
	int i,j,l=strlen(a);
	char t;//注意不要习惯性的写成了 int t;
	for(i=0;i<l-1;i++)
	 for(j=0;j<l-1;j++)
	 {
    
    
	 	if(a[j]>a[j+1])
	 	{
    
    
	 		t=a[j];
	 		a[j]=a[j+1];
	 		a[j+1]=t;
		  } 
	 }
	 for(i=0;i<l;i++)
	 {
    
    
	 	if(a[i]!=a[i+1]) printf("%c",a[i]);
	 }
	 return 0;
 } 

Welcome to the advice of the big guys, if you don’t understand the cute ones, you can privately message q2651877067, I am very happy to answer QwQ for you! ! !

Guess you like

Origin blog.csdn.net/mmmjtt/article/details/114368855