2 条题解
-
0
统计各个字符串出现次数进行判断
#include <iostream> #include <vector> #include <set> #include <algorithm> using namespace std; #define int long long const int mod=1e+7; signed main() { iostream::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s;cin>>s; vector<int> a(128); for(int i=0;i<s.length();i++){ a[s[i]]++; } int ans=0,num=0; for(int i=0;i<128;i++){ ans+=a[i]/2*2; if(a[i]%2==1)num++; } if(num>0){ ans++; } cout<<ans<<endl; return 0; }
-
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); int[] arr = new int[200]; for (int i = 0; i < str.length(); i++) { arr[str.charAt(i) - 'A']++; } int ans = 0; int flag = 0; for (int i = 0; i < 200; i++) { ans += arr[i] / 2 * 2; arr[i] %= 2; if(arr[i] == 1) flag = 1; } if(flag == 1) ans++; System.out.println(ans); } }
- 1
信息
- ID
- 597
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- (无)
- 递交数
- 195
- 已通过
- 48
- 上传者