题解 | 找位置

#include<iostream>
#include<unordered_set>
#include<string>
using namespace std;

int main(){
	string s1;
	while(cin>>s1){
		unordered_set<char> mySet;
		for(int i = 0;i<s1.length();i++){
			char ch = s1[i];
			auto it = mySet.find(ch);
			if(it!=mySet.end()){
				//该元素已经存在,可以直接跳过
			}else{
				bool flag = false;
				mySet.insert(ch);
				int count = 0;
				for(int j = i + 1;j<s1.length();j++){
					if(ch==s1[j]){
						count++;
						flag = true;
						if(count==1) cout<<ch<<":"<<to_string(i);
						cout<<",";
						cout<<s1[j]<<":"<<to_string(j);
					}
				}
				if(flag) cout<<endl;
			}
		}
	}
}

全部评论

相关推荐

渴望wlb的牛油果很...:直说卡第一学历不就行了 非得拐弯抹角
点赞 评论 收藏
分享
09-01 11:31
门头沟学院 Java
buul:七牛云的吧,感觉想法是好的,但是大家没那么多时间弄他这个啊。。。不知道的还以为他是顶尖大厂呢还搞比赛抢hc,只能说应试者的痛苦考察方是无法理解的,他们只会想一出是一出
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务