Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.6 kB
3
Indexable
Never
#include <bits/stdc++.h>

using namespace std;

class MySet{
private:
	int numBuckets;
	int numElements;
	vector<vector<string>> buckets;

	int hashString(string str){
		int raw = 0;
		for (auto l: str){
			raw += (int) l;
		}

		return raw % numBuckets;
	}

public:
	MySet(){
		numBuckets = 15000;
		numElements = 0;
		buckets = vector<vector<string>>(numBuckets, vector<string>{});
	}

	int size(){
		return numElements;
	}

	void add(string key){
		int i = hashString(key);
		if (find(buckets[i].begin(), buckets[i].end(), key) == buckets[i].end()){
			numElements++;
			return buckets[i].push_back(key);
		}
	}
};


int main(){
	
	int T, count = 0;
	cin >> T;
	while(count < T){
		int M, N;
		cin >> M >> N;

		vector<string> A;
		for (int i = 0; i < M; i++){
			string input;
			cin >> input;
			A.push_back(input);
		}

		vector<string> B;
                for (int i = 0; i < N; i++){
                        string input;
                        cin >> input;
                        B.push_back(input);
                }

		MySet C = MySet();
		for (int i = 0; i < M; i ++){
			string setString = A[i];
			for (int j = 0; j < N; j++){
				string comb = setString;
				comb.append(B[j]);

				//cout << "Combinação: " << comb << endl;
				C.add(comb);
			}
		}

		if (M == 0){
			cout << "Case " << count + 1 << ": " << B.size() << endl;
		}
		else if (N == 0){
			cout << "Case " << count + 1 << ": "<< A.size() << endl;
		}
		else{
			cout << "Case " << count+1 << ": " << C.size()<< endl;
		}
		//cout << A.countElements() << endl;
		//cout << B.countElements() << endl;

		count ++;
	}
	return 0;
}