题解 | 找位置

#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;
			}
		}
	}
}

全部评论

相关推荐

代码飞升_不回私信人...:别这样贬低自己,降低预期,放平心态,跟昨天的自己比。做好自己,反而会效率更高心态更好,加油兄弟
点赞 评论 收藏
分享
程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
985本硕1个中小厂of...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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