想了很久,不知道怎么写才对,后来翻教材直接找了两个库函数,几行代码就解决了
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int flag = 0;
char num[100001];//字符上限
cin.getline(num,100001);//结束符也会写到字符串里
for(int i=0,j=0;num[i];i++)
{
if(strchr(num,int(num[i]))==strrchr(num,int(num[i])))
{
cout<<num[i];
flag = 1;
break;
}
}
if(flag==0)
cout<<"no";
return 0;
}