64,674
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int IsExist(vector<char> c, char s)
{
if (c.size() == 0)
return -1;
for (int i = 0; i < c.size(); i++)
{
if (c[i] == s)
return i;
}
return -1;
}
bool SN(const char *s)
{
string st(s);
int n = st.length();
vector<char> c;
vector<int> q;
for (int i = 0; i < n; i++)
{
int index = IsExist(c, st[i]);
if (index > -1)
q[index]++;
else
{
c.push_back(st[i]);
q.push_back(1);//这儿改成这样子
}
}
if (n % 2 == 0)
{
for (int i = 0; i < q.size(); i++)
{
if (q[i] % 2 != 0)
return 0;
}
return 1;
}
else
{
int temp = 0;
for (int i = 0; i < q.size(); i++)
{
if (q[i] % 2 != 0)
temp++;
}
if (temp == 1)
return 1;
else
return 0;
}
}
int main()
{
cout << "input a string : " << endl;
string t;
cin >> t;
const char* s = t.c_str();
cout << SN(s) << endl;
system("pause");
}
#include<iostream>
#include<vector>
#include<string>
using namespace std;
void main()
{
int check[26];
for(int i = 0;i<26;i++)
check[i] = 0;
string str;
cin>>str;
for(int i = 0;i<str.size();i++)
check[(str.c_str())[i]-'a']++;
int flag(0);
if(str.size() % 2 == 0)
flag = 0;
else
flag = 1;
for(int i = 0;i<26;i++)
{
if(check[i] % 2 == 1)
flag--;
}
if(flag < 0)
cout<<"0"<<endl;
else
cout<<"1"<<endl;
system("pause");
}