民生银行2021民芯计划笔试题求解答

题目描述:

给定n个仅由小写字母构成的字符串。定义两个字符串是否是等价的当且仅当可以通过重新排列一个字符串得到另一个字符串,如abc和cba是等价的。

一个字符串集合被称为好的当且仅当这个集合里的字符串两两等价,求这n个字符串能得到的最大的好的字符串集合的大小。

输入描述:

第一行一个数字n。

接下来n行,每行一个字符串,第i行表示字符串si。

1<=n<=10000,Σ|si|<=3*10000

输出描述:

一行一个数字表示答案
例如:
输入
6
abc
acb
bac 
bca
cba
cab
(本人实在太菜,未全部AC,提示超时)求大佬解答
#民生银行未来银行家##民生银行##笔试题目#
全部评论
用的什么语言
1 回复
分享
发布于 2020-07-12 21:24
#include<iostream> #include<stdlib.h> #include<vector> #include<map> #include<set> #include<iterator> #include<string> #include <algorithm> #include <iostream> #include <vector> using namespace std; void sortString(string& s){     sort(s.begin(),s.end()); } int main() {     int n;     vector<string> vec;     cin >> n;     for(int i = 1; i <= n ; ++i){         string s;         cin >> s;         vec.push_back(s);     }     map<string> mp;     for(auto s : vec){         sortString(s);         if(mp.find(s) == mp.end())             mp[s] = 1;         else             mp[s] += 1;     }     int res = 0;     for(auto iter = mp.begin(); iter != mp.end(); ++iter)         res = max(res,iter->second);     cout << res << endl; }</string></string></vector></iostream></algorithm></string></iterator></set></map></vector></stdlib.h></iostream>
点赞 回复
分享
发布于 2020-07-12 21:29
联想
校招火热招聘中
官网直投
哈希表统计,求最大值
点赞 回复
分享
发布于 2020-07-13 08:33
用hash,得自己定义下hash函数
点赞 回复
分享
发布于 2020-07-13 19:33
func GetHashString(str string) string{ // 等同的字符串为同字符 charTable := make([]int,256) for i := 0 ; i < len(str);i++{ charTable[str[i]] ++ } var result = "" for i := 0; i < 256;i++{ if charTable[i] > 0 { result += fmt.Sprintf("%c%d",byte(i),charTable[i]) } } return result }
点赞 回复
分享
发布于 2020-07-13 19:36
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashMap; import java.util.Map; public class goodStrings {     public static void main(String[] args) throws IOException {         Map<String, Integer> map = new HashMap<>();         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));         String line = br.readLine();         int n = Integer.parseInt(line);         int res = 0;         for(int i = 0; i < n; i++) {             String str = br.readLine();             char[] t = str.toCharArray();             System.out.println(t);             Arrays.sort(t);             str = new String(t);             map.put(str, map.getOrDefault(str, 0) + 1);             res = Math.max(res, map.get(str));         }         System.out.println(res);     } }
点赞 回复
分享
发布于 2021-06-22 17:41
请问民心计划的产品经理岗也要编程吗
点赞 回复
分享
发布于 2021-06-22 19:18
不知道我写的会不会也超时 public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         int n = Integer.parseInt(sc.nextLine());         int[] alpha = new int[26];         String[] strs = new String[n];         for (int i = 0; i < n; i++)              strs[i] = sc.nextLine();         HashMap<String,Integer> hashMap = new HashMap<>();         for (int i = 0; i < n; i++) {             Arrays.fill(alpha , 0 );             String tmpStr = strs[i];             for (int j = 0; j < tmpStr.length(); j++)                  alpha[tmpStr.charAt(j) - 'a&(417)#39;]++;             String string = "";             for (int j = 0; j < 26; j++)                  string = string + "_" + alpha[j];             hashMap.put(string , hashMap.getOrDefault(string , 0 )+ 1);         }         int res = 0 ;         for (String string : hashMap.keySet()) {             if(hashMap.get(string) > res){                 res = hashMap.get(string);             }         }         System.out.println(res);     }
点赞 回复
分享
发布于 2021-06-26 16:27

相关推荐

2 20 评论
分享
牛客网
牛客企业服务