C++ STL 中set
#include<string>
set<string>s;
string str = "ABCD";
if(s.find(str) != s.end()) //iterator find(value)返回value所在位置,找不到value将返回end()
printf(“str已经存在!\n”);
else s.insert(str); //添加string str
java 中 set
Set<String> set = new HashSet<String>(); String s = "ABCD"; if(set.contains(s)) System.out.println(“str已经存在”); else set.add(s);