lz是刷题萌新,这篇是写给自己用作记录的,大佬们如果不小心看到了可以帮我提提修改意见吗
一些非常耗时且费空间的100分解法↓难点居然是在这个输入如何处理换行符上!
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
string words1;
string words2;
cin.ignore(1, '\n');
getline(cin, words1);
getline(cin, words2);
vector<string> dic1;
vector<string> dic2;
vector<string> newdiction1;
vector<string> newdiction2;
int index = 0;
for (int i = 0; i < words1.length(); i++)
{
if (i == 0) { dic1.push_back(""); }
if (words1[i] == ' ') { index++; dic1.push_back("");}
else
{
if (words1[i] >= 'A' && words1[i] <= 'Z')
{
words1[i] = (char)(words1[i] - ('A' - 'a'));
}
dic1[index] += words1[i];
}
}
index = 0;
for (int i = 0; i < words2.length(); i++)
{
if (i == 0) { dic2.push_back(""); }
if (words2[i] == ' ') { index++; dic2.push_back(""); }
else
{
if (words2[i] >= 'A' && words2[i] <= 'Z')
{
words2[i] = (char)(words2[i] - ('A' - 'a'));
}
dic2[index] += words2[i];
}
}
//去重
for (int i = 0; i < dic1.size()-1; i++)
{
for (int j = i+1; j < dic1.size(); j++)
{
if (dic1[i] == dic1[j])
{
dic1[j] = "";
}
}
}
for (int i = 0; i < dic2.size() - 1; i++)
{
for (int j = i + 1; j < dic2.size(); j++)
{
if (dic2[i] == dic2[j])
{
dic2[j] = "";
}
}
}
//加入字典中
for (int i = 0; i < dic1.size(); i++)
{
if (dic1[i] != "")
{
newdiction1.push_back(dic1[i]);
}
}
for (int i = 0; i < dic2.size(); i++)
{
if (dic2[i] != "")
{
newdiction2.push_back(dic2[i]);
}
}
//两个字典比较
int _union = 0;
int _conjunc = 0;
for (int i = 0; i < newdiction1.size(); i++)
{
for (int j = 0; j < newdiction2.size(); j++)
{
if (newdiction1[i] == newdiction2[j]) { _union--; _conjunc++; }
}
}
cout << _conjunc << endl;
cout << newdiction1.size() + newdiction2.size() + _union ;
return 0;
}