携程旅行2019年春招-研发方向B-编程第一道

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Lydia_r/article/details/89108110

给定一个链表,判断是否有环

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

猜你喜欢

转载自blog.csdn.net/Lydia_r/article/details/89108110