给定一个链表,判断是否有环
eg:a,b,c,d
输出 false
eg:a,b,c,d,a
输出:true
大致是这个意思,我忘了截图
#include <iostream>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;
const int N=1010;
int main(){
ios::sync_with_stdio(false);
char str[N],tmp[N];
int i,j,flag;
cin>>str;
j=0;
for(i=0;i<strlen(str);i++){
if(str[i]!=','){
tmp[j]=str[i];
++j;
}
}
sort(tmp,tmp+j);
flag=0;
for(i=0;i<j-1;i++){
if(tmp[i]==tmp[i+1]){
flag=1;
break;
}
}
if(flag==1)
cout<<"true"<<endl;
else
cout<<"false"<<endl;
return 0;
}