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

include "stdafx.h"

include

include

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

posted @ 2017-03-16 18:54  wdan2016  阅读(186)  评论(0)    收藏  举报