我有不同类型的字符串,我需要找出这个字符串中的重复条目。 不同类型的字符串在C++中查找字符串中的重复条目
string aStr= "1.1,1.2,1.3, 1"; //output should be duplicate entry
string aStr= "1.1,1.2,1.3"; //Ouput NO duplicate entry
string aStr= "1,2,1"; //o/p duplicate entry
string aStr = "1,2,3";//output No duplicate
I have tried as
std::vector <std::string> aOutString;
std::set <int> full_list;
std::set <std::string> aEntryInDouble;
int aNum1;
boost::split(aOutString, aStr , boost::is_any_of(","));
for(size_t it = 0; it < aOutString.size(); ++it)
{
if (aOutString[it].find('.') != std::string::npos)
{
//If entry is like "1.1,1.2,1.3"
if(!aEntryInDouble.insert(aOutString[it]).second)
{
aDup = false;
break;
}
}
else
{
//For entry "1,2,1"
aNum1 = std::atoi(aOutString[it].c_str());
if(aNum1)
{
if(!full_list.insert(aNum1).second)
{
aDup = false;
break;
}
}
- 的我无法找出适合入门字符串“字符串而aStr =‘1.1,1.2,1.3,1’解决方案; 请帮我找出解决办法。
感谢,
是什么让你无法?你遇到什么具体问题? –
你为什么明确地处理'.'?该算法看起来很简单:用逗号分隔。从分割列表创建一个集合。如果这个集合的长度等于分割列表的长度,那么不会有任何愚蠢的行为。 – erip
请把这个任务的文本放在这里。例如,定义“重复”。 – Les