您的位置:首页 > 其它

你要的最后一个字符就在下面这个字符串里,这个字符是下面整个字符串中第一个只出现一次的字符。(比如,串是abaccdeff,那么正确字符就是b了)

2017-03-16 18:54 645 查看

include "stdafx.h"

#include<iostream>

#include<string>
using namespace std;

int main()
{
int num;
cin >> num;
while (num!=0)
{
num--;
string str;
//  getline(cin,str);
cin >> str;
int flag = 0;
for (int i = 0;i < str.length();i++)
{
bool result = true;
for (int j = 0;j < str.length();j++)
{
/*  cout << "i:" << i<<" ";
cout << "j:" << j << endl;*/
if (i == j) continue;
if (str[i] == str[j])
{
//  cout << "执行了" << endl;
result = false;
break;
}
}

if (result == true)
{
//      cout << "执行了" << endl;
flag = i;
//      cout << "flag:"<<flag << endl;
break;
//  cout << str[i] << endl;
}
}

cout << str[flag] << endl;

}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐