您的位置:首页 > 其它

出一个字符中只出现过一次且是出现一次的字符串中最先出现的字符

2015-08-16 22:51 323 查看
找出一个字符中只出现过一次且是出现一次的字符串中最先出现的字符:

下面的代码在vc6.0上面编译要出问题,只能说,vc6.0 不适合写c++的代码,除了内存占用小点,没什么好处

#include <iostream>
#include <string>

using namespace std;

int main()
{
int n ;
string str;
cin>>n;
//getchar();
while(n > 0)
{
n -- ;
getline(cin,str,'\n');
//	getchar();
int len = str.size();
cout<<len<<endl;
int strarr[256] = {0};
int pos = -1;
for(int i = 0 ; i < len ; i ++)
{
strarr[str[i]] ++;
}

for(int j = 0 ; j < len ; j ++)
{
if(strarr[str[j]] == 1)
{
pos = j ;
break;
}
}
if(pos != -1)
cout<<str[pos];
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: