查找重复的字符串
来源:互联网 发布:流动人口定时联系软件 编辑:程序博客网 时间:2024/04/27 14:32
给定一个长度为n的数组,其元素也在【0 n-1】范围内,判断其中是否包含重复元素。
#include <stdio.h>
#include <stdlib.h>#include<iostream>
#include<string>
using namespace std;
bool find_repeat(int *s,int len)
{
int max(s[0]),min(s[0]);
if(len==0)
return false;
for(int i=1;i<len;i++)
{
if(s[i]>max)
{
max=s[i];
}
else if(s[i]<min)
{
min=s[i];
}
}
int temp=max-min;
if(temp==0)
{
return true;
}
for(int i=0;i<len;i++)
{
s[i]=s[i]-min;
}
//int i=0;
for(int i=0;i<len;i++)
{
while(s[i]!=i)
{
if(s[s[i]]==s[i])
return true;
else
{
int temp=s[i];
s[i]=s[temp];
s[temp]=temp;
}
}
}
return false;
}
int main()
{
int a[]={3,5,2,-1,1,0,4};
if(find_repeat(a,7))
cout<<"repeat true"<<endl;
else
cout<<"no repeat"<<endl;
for(int i=0;i<7;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}
0 0
- 查找重复的字符串
- 查找字符串中重复出现的数据
- 查找重复次数最多的子字符串
- 字符串查找第一个不重复的字符的实现
- 查找最长重复子字符串
- 在字符串中查找最长重复子串的探讨
- ASP.NET正则表达式查找字符串中重复的字符
- ASP.NET正则表达式查找字符串中重复的字符
- 查找字符串中第一次重复的字符 java
- 查找字符串中第一次不重复的字符 java
- 查找字符串中第一个不重复的字符
- 查找字符串中最长无重复字符的子串
- 查找字符串中最长重复字符的子串
- java实现查找数组中重复次数最多的字符串
- 查找字符串中第一个不重复的字符
- 查找字符串中无重复最长子串的长度
- 查找字符串中重复的子串,并输出重复的次数
- 查找重复的索引
- java实现树的前序,中序,后序的递归和非递归遍历
- 工作流jbpm4的学习笔记1
- 为 Android private library 指定source和java doc
- 征服 Redis + Jedis + Spring (一)—— 配置&常规操作(GET SET DEL)
- CentOS 重启时出现 “Give root password for maintenance” 错误的解决办法
- 查找重复的字符串
- c#针对任何数值类型的排序算法
- [Ai工程文件] 超详细!手把手教你用AI创建细节丰富的404页面
- VC6之dll编程总结
- 解决webrtc2sip编译出现错误undefined reference to symbol 'dlopen@@GLIBC_2.1'
- Linux 命令英文全称
- Android 让EditText失去焦点避免自动弹出输入法
- Sniffer含义及工作原理
- 关于IM即使通讯