code[vs] 1485 字符配对

来源:互联网 发布:优化发展环境情况汇报 编辑:程序博客网 时间:2024/06/16 02:01
http://codevs.cn/problem/1485/



#include <iostream>#include <string>using namespace std ;int main(){string s ;cin >> s ;int len = s.size();int count[26] ={0} ;    int sum = 0 ;    for ( int i = 0 ; i < len ;++i)             count[s[i]-'a']++;    for ( int i = 0 ; i < 26 ; ++i)        {          if(count[i]==1 || count[i]==0) sum += 0 ;          if( count[i] >= 2 && count[i]%2 == 0) sum += count[i] ;          if(count[i] >= 2 && count[i]%2  != 0) sum += count[i] -1 ;        }    cout << len - sum << endl;    return 0 ;     }


0 0