对给定的一个字符串,找出有重复的字符串,并给出其位置

#include<stdio.h>
#include<string.h>
int main(){
    
    
	char str[100]={
    
    "abcaaAB12ab12"};
	int len=strlen(str);
	int b[100]={
    
    0};
	for(int i=0;i<len-1;i++){
    
    
		for(int j=i+1;j<len;j++){
    
    
			if(str[i]==str[j]){
    
    
				if(b[i]==0){
    
    
					printf("%c  %d ",str[i],i+1);
					b[i]=1;
				}
				if(b[j]==0){
    
    
					printf("%c  %d ",str[j],j+1);
					b[j]=1;
				}
			}
		}
	}
	
}

猜你喜欢

转载自blog.csdn.net/qq_45560230/article/details/129382153
今日推荐