【PAT乙级】刷题记录(C++)

水平差,更新慢,指不定哪天就停了,希望别

1001 害死人不偿命的(3n+1)猜想

#include <iostream>
using namespace std;

int main()
{
	int n;
	int cnt = 0;
	cin >> n;
	while (n != 1)
	{
		if (n % 2 == 0)
			n /= 2;
		else
			n = (3 * n + 1) / 2;
		cnt++;
	}
	cout << cnt;
	return 0;
}

1002 写出这个数

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string a[10] = { "ling","yi","er","san" ,"si" ,"wu" ,"liu" ,"qi" ,"ba" ,"jiu" };
	string in;
	cin >> in;
	int ans = 0;
	for (int i = 0; i < in.length(); i++)
	{
		ans += in[i] - '0';
	}
	string tmp = to_string(ans);
	for (int i = 0; i < tmp.length()-1; i++)
	{
		cout << a[tmp[i] - '0'] << " ";
	}

	cout << a[tmp[tmp.length()-1] - '0'];
	return 0;
}

1004 成绩排名

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int cmp(const pair<string, pair<string, int> >& a, const pair<string, pair<string, int> >& b)
{
    return a.second.second > b.second.second;
}

void sortMap(map<string, pair<string, int> >& m, vector < pair<string, pair<string, int> > > &v)
{
    for (map<string, pair<string, int> >::iterator it = m.begin(); it != m.end(); it++)
        v.push_back(*it);
    sort(v.begin(), v.end(), cmp);
}

int main()
{
    int n;
    cin >> n;
    map<string, pair<string, int> > stu;
    while (n--) {
        string name, id;
        int grade;
        cin >> name >> id >> grade;
        stu.insert(make_pair(id, make_pair(name, grade)));
    }
    vector < pair<string, pair<string, int> > > tmp;
    sortMap(stu, tmp);
    //for (vector<pair<string, pair<string, int> > >::iterator it =tmp.begin();
    //    it != tmp.end(); it++)
    //{
    //    cout << it->first << " " << it->second.first << " " << it->second.second << endl;
    //}

    //for (map<string, pair<string, int> >::iterator it = stu.begin(); it != stu.end(); it++)
    //{
    //    cout << it->first << " " << it->second.first << " " << it->second.second << endl;
    //}

    /*这里只要求最高、最低,其实也不用全部排序,找出最高最低的序号就行了
    排序的话就是更加全面一点
	*/

    /*map<string, pair<string, int> >::iterator it = stu.begin();
    cout << it->second.first << " " << it->first << endl;
    map<string, pair<string, int> >::reverse_iterator rt = stu.rbegin();
    cout << rt->second.first << " " << rt->first << endl;*/

    //cout << tmp.size();
    //cout << n - 1;

    cout << tmp[0].second.first << " " << tmp[0].first << endl;
    cout << tmp[tmp.size() - 1].second.first << " " << tmp[tmp.size()-1].first << endl;
    /*
    while (it != stu.end())
    {
        it++;
    }
    cout << it->second.first << " " << it->first << endl;*/

    return 0;
}

1006 换个格式输出整数

#include <iostream>
#include<string>
using namespace std;

int main()
{
	int n;
	cin >> n;
	if (n < 10) {
		for (int i = 1; i <= n; i++)
			cout << i;
	}
	else if (n < 100)
	{
		int cnt10 = n / 10;
		int rest = n % 10;
		for (int i = 0; i < cnt10; i++)
			cout << 'S';
		for (int i = 1; i <= rest; i++)
			cout << i;
	}
	else
	{
		int cnt100 = n / 100;
		n %= 100;
		int cnt10 = n / 10;
		int rest = n % 10;
		for (int i = 0; i < cnt100; i++)
			cout << 'B';
		for (int i = 0; i < cnt10; i++)
			cout << 'S';
		for (int i = 1; i <= rest; i++)
			cout << i;

	}
	return 0;
}

1007 素数对猜想

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int isPrime(int k) {
    for (int i = 2; i < sqrt(k) + 1; i++) {
        if (k % i == 0) return 0;
    }
    return 1;
}

int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    int primes[9600] = { 0 };
    primes[0] = 2;
    primes[1] = 3;
    int tmp = 2;
    for (int i = 5; i < 100000; i++) {
        if (isPrime(i)) {
            primes[tmp++] = i;
        }
    }
    //cout << tmp;
    //for (int i = 0; i < 100; i++) cout << primes[i] << " ";
    for (int i = 1; i < tmp ; i++) {
        if (primes[i] > n) break;
        if (primes[i] - primes[i - 1] == 2)
            cnt++;
    }
    cout << cnt;
    return 0;
}

1008 数组元素循环右移问题

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    m = m % n;
    int* a = new int[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++) {
        cout << a[(n - m + i) % n];
        if (i != n - 1) cout << " ";
    }

    return 0;
}

1009 说反话

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

//高效的string分割函数
void split(const string& str, vector<string>& v, const string& substr)
{
    int pos1, pos2;
    pos2 = str.find(substr);
    pos1 = 0;
    while (pos2!=string::npos) 
    {
        v.push_back(str.substr(pos1, pos2 - pos1));//substr函数的两个参数分别是,起始位置+长度
        pos1 = pos2 + substr.size();
        pos2 = str.find( substr,pos1);
    }
    if (pos1 != str.size())
    {
        v.push_back(str.substr(pos1,pos2))  ;
        //比如是空格分割,如果string str最后没有空格
        //那么前面的while循环结束后,还有一个pos1后面的子字符串需要压栈
    }
}

int main()
{
    //string s;
    //cin >> s;
    //while (s[0] !='\n' ) {
    //    //cout << int(s[0]) << endl;
    //    str.push_back(s);
    //    cin >> s;
    //}

    string str;
    getline(cin, str);
    vector<string> v;
    split(str, v, " ");
    for (int i = v.size()-1; i >=0; i--) {
        cout << v[i] ;
        if (i != 0) cout << " ";
    }

    /*for (vector<string>::iterator it = str.begin(); it != str.end(); it++) {
        cout << *it << endl;
    }*/

    return 0;
}

1011 A+B 和 C

#include <iostream>
#include<string>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int cnt = 0;
	while (cnt!=n)
	{
		cnt++;
		double a;
		double b;
		double c;
		cin >> a >> b >> c;
		if (a + b > c)
			cout << "Case #" << cnt << ": true";
		else
			cout << "Case #" << cnt << ": false";
		cout << endl;
		
	}
	return 0;
}

1012 数字分类

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

//关于c++四舍五入保留小数的n种方法:
//https://blog.csdn.net/jacketinsysu/article/details/52434669
int main()
{
    int n;
    cin >> n;
    int* a = new int[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0;
    int a2_flag = 1;

    int a1_cnt = 0;
    int a2_cnt = 0;
    int a3_cnt = 0;
    int a4_cnt = 0;
    int a5_cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] % 5 == 0 && a[i] % 2 == 0) {
            a1 += a[i];
            a1_cnt++;
            continue;
        }
        if (a[i] % 5 == 2) {
            a3++;
            a3_cnt++;
            continue;
        }
        if (a[i] % 5 == 4 && a[i]>a5) {
            a5 = a[i];
            a5_cnt++;
            continue;
        }
        if (a[i] % 5 == 3) {
            a4 += a[i];
            a4_cnt++;
            continue;
        }
        if (a[i] % 5 == 1) {
            a2 += a[i] * a2_flag;
            a2_flag *= -1;
            a2_cnt++;
            continue;
        }
    }
    if (a1_cnt == 0) {
        cout << "N ";
    }
    else {
        cout << a1;
        cout << " ";
    }
    if (a2_cnt == 0) {
        cout << "N ";
    }
    else {
        cout << a2;
        cout << " ";
    }
    if (a3_cnt == 0) {
        cout << "N ";
    }
    else {
        cout << a3;
        cout << " ";
    }
    if (a4_cnt == 0) {
        cout << "N ";
    }
    else {
        float a4_f = float(a4) / float(a4_cnt);
        float a4_f_10 = (a4_f * 10 + 0.5);
        int tmp = floor(a4_f_10);
        float a4_new = float(tmp) / 10;
        cout << a4_new << " ";
    }
    if (a5_cnt == 0) {
        cout << "N";
    }
    else {
        cout << a5;
    }
    return 0;
}

1013 数素数

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int isPrime(int n) {
    for (int i = 2; i < sqrt(n) + 1; i++)
    {
        if (n % i == 0)
            return 0;
    }
    return 1;
}

int main()
{
    int m, n;
    cin >> m >> n;
    int primes[120000] = { 0 };
    primes[0] = 2;
    primes[1] = 3;
    int cnt_prime = 2;
    for (int i = 5; i < 120000; i++)
    {
        if (cnt_prime > 10000)
            break;
        if(isPrime(i))
            primes[cnt_prime++] = i;
    }
    int cnt10 = 0;
    for (int i = m - 1; i < n; i++)
    {
        cout << primes[i];
        cnt10++;
        if (cnt10 %10== 0) {
            cout << endl;
        }
        else if(cnt10 !=n-m+1 ){
            cout << " ";
        }
    }
    //for (int i = 0; i < 100; i++)
        //cout << primes[i] << " ";
    return 0;
}

1016 部分A+B

#include <iostream>
#include<string>
using namespace std;

int p(int a, int da)
{
	int cnt = 0;
	while (a) {
		int x = a % 10;
		if (x == da)
			cnt++;
		a /= 10;
	}
	if (cnt == 0) return 0;
	int ans = 0;
	while (cnt)
	{
		ans *= 10;
		ans += da;
		cnt--;
	}
	return ans;
}

int main()
{
	int a, da, b, db;
	cin >> a >> da >> b >> db;
	cout << p(a, da) + p(b, db);
	return 0;
}

1017 A除以B

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

//int* divide(int a, int b)
//{
//    int ans[2] = { 0 };
//
//}
int main()
{
    string a;
    int b;
    cin >> a >> b;
    string ans = "";
    int shang = 0;
    int yu = 0;
    for (int i = 0; i < a.length(); i++)
    {
        ans += to_string(shang);
        int ai_new = yu * 10 + (a[i]-'0');
        shang = ai_new / b;
        yu = ai_new % b;
    }
    int flag_start = 1;
    for (int i = 0; i < ans.length(); i++)
    {
        if (flag_start == 1 && ans[i] == '0')
        {
            continue;
        }
        flag_start = 0;
        cout << ans[i];
    }
    cout << shang;
    cout<<" " << yu;
    return 0;
}

1018 锤子剪刀布

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    char* jia = new char[n];
    char* yi = new char[n];
    int jia_win = 0, jia_equal = 0, jia_lose = 0;
    int jia_cnt[3] = { 0 };
    int yi_cnt[3] = { 0 };
    for (int i = 0; i < n; i++)
    {
        cin >> jia[i] >> yi[i];
        if (jia[i] == 'C')
        {
            if (yi[i] == 'C')
            {
                jia_equal++;
            }
            else if (yi[i] == 'J')
            {
                jia_win++;
                jia_cnt[1]++;
            }
            else
            {
                jia_lose++;
                yi_cnt[0]++;
            }
        }
        else if (jia[i] == 'J')
        {
            if (yi[i] == 'J')
            {
                jia_equal++;
            }
            else if (yi[i] == 'B')
            {
                jia_win++;
                jia_cnt[2]++;
            }
            else
            {
                jia_lose++;
                yi_cnt[1]++;
            }
        }
        else if (jia[i] == 'B')
        {
            if (yi[i] == 'B')
            {
                jia_equal++;
            }
            else if (yi[i] == 'C')
            {
                jia_win++;
                jia_cnt[0]++;
            }
            else
            {
                jia_lose++;
                yi_cnt[2]++;
            }
        }
    }
    cout << jia_win << " " << jia_equal << " " << jia_lose << endl;
    cout << jia_lose << " " << jia_equal << " " << jia_win << endl;
    int max_jia = 0, max_yi = 0;
    char letter[3] = { 'B','C','J' };
    for (int i = 0; i < 3; i++)
    {
        int temp1 = max(jia_cnt[0], jia_cnt[1]);
        if (temp1 < jia_cnt[2])
        {
            max_jia = 2;
        }
        else
        {
            max_jia = (jia_cnt[0] >= jia_cnt[1]) ? 0 : 1;
        }
    }
    for (int i = 0; i < 3; i++)
    {
        int temp1 = max(yi_cnt[0], yi_cnt[1]);
        if (temp1 < yi_cnt[2])
        {
            max_yi = 2;
        }
        else
        {
            max_yi = (yi_cnt[0] >= yi_cnt[1]) ? 0 : 1;
        }
    }
    cout << letter[max_jia] << " " << letter[max_yi];
    //cout << max_jia << endl;
    //cout << jia_cnt[0] << " " << jia_cnt[1] << " " << jia_cnt[2];
    return 0;
}

1021 个位数统计

#include <iostream>
#include<string>
#include<map>
using namespace std;

int main()
{
	map<int, int> ans;
	for (int i = 0; i <= 9; i++)
	{
		ans.insert(pair<int,int>(i, 0));
	}
	string k;
	cin >> k;
	for (int i = 0; i < k.length(); i++)
	{
		int tmp = k[i] - '0';
		ans[tmp]++;
	}
	for (map<int, int>::iterator iter = ans.begin(); iter != ans.end(); iter++)
	{
		if (iter->second > 0)
			cout << iter->first << ":" << iter->second << endl;
	}
	//for (int i = 0; i <= 9; i++)
	//{
	//	if (ans[i] != 0)
	//		cout << i << ":" << ans[i] << endl;
	//}
	return 0;
}

1022 D进制的A+B

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;


int main()
{
    int a, b, d;
    cin >> a >> b >> d;
    int c = a + b;
    string ans = "";
    int di = 1;
    int shang=1000, yu=1000;
    while (shang)
    {
        shang = c / d;
        yu = c % d;
        ans += to_string(yu);
        c = shang;
    }
    //cout << ans;
    for (int i = ans.length() - 1; i >= 0; i--)
        cout << ans[i];
    return 0;
}

1023 组个最小数

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

bool cmp(int& a, int& b)
{
    return a < b;
}

int main()
{
    vector<int> v;
    int cnt[10] = { 0 };
    for (int i = 0; i < 10; i++)
    {
        cin >> cnt[i];
    }
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < cnt[i]; j++)
        {
            v.push_back(i);
        }
    }
    sort(v.begin(), v.end(), cmp);
    //for (int i = 0; i < 10; i++)
    //{
    //    cout << v[i] << " ";
    //}
    int flag = 1;
    for (int i = 0; i < v.size(); i++)
    {
        if (flag == 1 && v[i] == 0)
        {
            continue;
        }
        if (flag == 1 && v[i] != 0)
        {
            swap(v[i], v[0]);
            flag = 0;
        }
    }
    for (int i = 0; i < v.size(); i++)
        {
        cout << v[i];
        }
    return 0;
}

1026 程序运行时间

#include<iostream>
#include<string>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;

int main()
{
	double s, e;
	cin >> s >> e;
	double tmp = e - s;
	int h = tmp / 360000;
	tmp -= h * 360000;
	int m = tmp / 6000;
	double second = tmp - m * 6000;
	int ss = round(second / 100);
	printf("%02d:%02d:%02d", h, m, ss);
	//if (h == 0)
	//{
	//	if (m == 0) {
	//		cout << setw(2) << second;
	//	}
	//	else
	//	{
	//		cout << setw(2) << m << ":" << setw(2) << second;
	//	}
	//}
	//else
	//{
	//	cout << setw(2) << h << ":" << setw(2) << m << ":" << setw(2) << second;
	//}
	/*
	https://blog.csdn.net/aouixh/article/details/53483556?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
	ceil()、floor()、round()
	double floor(double x);

double ceil(double x);

使用floor函数。floor(x)返回的是小于或等于x的最大整数。
如:     floor(10.5) == 10    floor(-10.5) == -11


使用ceil函数。ceil(x)返回的是大于x的最小整数。
如:     ceil(10.5) == 11    ceil(-10.5) ==-10


floor()是向负无穷大舍入,floor(-10.5) == -11;
ceil()是向正无穷大舍入,ceil(-10.5) == -10
round()函数是四舍五入,除了直接用round函数外,还可以用floor实现四舍五入:
    int time=floor((C2-C1)/CLK_TCK+0.5);//floor实现四舍五入 
*/

	return 0;
}

1028 人口普查

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

struct person {
	string name;
	int year;
	int mon;
	int day;
};

int cmp(person& a, person& b)
{
	if (a.year != b.year)
	{
		return a.year > b.year;
	}
	else
	{
		if (a.mon != b.mon)
		{
			return a.mon > b.mon;
		}
		else {
			return a.day > b.day;
		}
	}
}

int main()
{
	int n;
	cin >> n;
	vector<person> people(n);
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> people[i].name;
		string temp;
		cin >> temp;
		string year = temp.substr(0, 4);
		string mon = temp.substr(5, 2);
		string day = temp.substr(8, 2);
		const char* ch = year.c_str();
		int y = atoi(ch);
		ch = mon.c_str();
		int m = atoi(ch);
		ch = day.c_str();
		int d = atoi(ch);
		if (y > 2014) continue;
		if (y == 2014 && m > 9) continue;
		if (y == 2014 && m == 9 && d > 6) continue;

		if (y < 1814) continue;
		if (y == 1814 && m < 9) continue;
		if (y == 1814 && m == 9 && d < 6) continue;


		people[i].year = y;
		people[i].mon = m;
		people[i].day = d;
		cnt++;

		//cout << people[i].name << " " << people[i].year << " " << people[i].mon << " " << people[i].day << endl;
	}

	sort(people.begin(), people.end(), cmp);
	cout << cnt;
	//for (int i = 0; i < cnt; i++)
	//{
	//	cout << people[i].name << " " << people[i].year << " " << people[i].mon << " " << people[i].day << endl;
	//}
	if(cnt>=1) cout <<" "<< people[cnt - 1].name << " " << people[0].name;
	return 0;
}

1031 查验身份证

#include <iostream>
#include<string>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;

char m[11] = { '1','0','X', '9', '8','7', '6', '5','4', '3','2' };
int weight[17] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
int main()
{
	int n;
	cin >> n;
	int all_pass = 1;
	while (n) {
		n--;
		string id;
		cin >> id;
		int sum = 0;
		int flag = 0;
		for (int i = 0; i < id.length()-1; i++)
		{
			if (id[i] - '0'<0 || id[i] - '0' >9)
			{
				cout << id << endl;//最后一行的换行符要不要考虑
				flag = 1;
				all_pass = 0;
				break;
			}
			sum += (id[i] - '0') * weight[i];
		}
		if (flag != 1) {
			int z = sum % 11;
			char check = m[z];
			if (check != id[17])
			{
				cout << id << endl;
				all_pass = 0;
			}
		}
		
	}
	if (all_pass == 1)
		cout << "All passed";
	return 0;
}

/*
记住ASCII码中常用的部分,比如,0是从48开始的,A是从65开始,a是从97开始
*/

1032 挖掘机技术哪家强

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int cmp(pair<int, int>& a, pair<int, int>& b)
{
	return a.second > b.second;
}

void sortMap(map<int, int>& m, vector<pair<int, int> >& v)
{
	map<int, int>::iterator it;
	for (it = m.begin(); it != m.end(); it++)
	{
		v.push_back(*it);
	}
	sort(v.begin(), v.end(), cmp);
}
int main()
{
	int n;
	cin >> n;
	map<int, int> school;
	for (int i = 0; i < n; i++)
	{
		int id, score;
		cin >> id >> score;
		if (school.find(id) != school.end())
		{
			school.find(id)->second += score;
		}
		else
		{
			school.insert(make_pair(id, score));
		}
	}
	vector<pair<int, int> > v;
	sortMap(school, v);
	//cout << school.size();
	cout << v[0].first << " " << v[0].second;
	return 0;
}

1036 跟奥巴马一起编程

#include <iostream>
#include<string>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	char ch;
	cin >> ch;
	for (int i = 0; i < n; i++)
		cout << ch;
	cout << endl;
	for (int row = 0; row < (round(double(n)/2)) - 2; row++)
	{
		cout << ch;
		for (int i = 0; i < n - 2; i++)
			cout << " ";
		cout << ch << endl;
	}
	for (int i = 0; i < n; i++)
		cout << ch;
	cout << endl;
	return 0;
}

1037 在霍格沃茨找零钱

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

void split(string a, vector<string> &v,char c)
{
	int pos1 = 0, pos2 = 0;
	pos2 = a.find(c, 0);
	while (pos2!=string::npos)
	{
		v.push_back(a.substr(pos1, pos2 - pos1));
		pos1 = pos2 + 1;
		pos2 = a.find(c, pos1);
	}
	if (pos1 != a.size())
	{
		v.push_back(a.substr(pos1, a.size() - pos1));
	}

}

int main()
{
	string a, b;
	cin >> a >> b;
	vector<string> va;
	vector<string> vb;
	split(a, va, '.');
	split(b, vb, '.');
	//for (int i = 0; i < v.size(); i++)
	//{
	//	cout << v[i] << " ";
	//}
	int aint = atoi(va[0].c_str()) * 17 * 29 + atoi(va[1].c_str()) * 29 + atoi(va[2].c_str());
	int bint = atoi(vb[0].c_str()) * 17 * 29 + atoi(vb[1].c_str()) * 29 + atoi(vb[2].c_str());
	int flag = 1;
	if (aint < bint)
	{
		flag = -1;
	}
	if (aint == bint)
	{
		cout << "0.0.0";
	}
	else
	{
		int cha = abs(aint - bint);
		int g, s, k;
		g = cha / (17 * 29);
		s = (cha - g * 17 * 29) / 29;
		k = cha - g * 17 * 29 - s * 29;
		if (flag == 1)
		{
			cout << "-";
		}
		cout << g << "." << s << "." << k;
	}
	return 0;
}

1039 到底买不买

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

void split(string a, vector<string>& v, char c)
{
	int pos1 = 0, pos2 = 0;
	pos2 = a.find(c, 0);
	while (pos2 != string::npos)
	{
		v.push_back(a.substr(pos1, pos2 - pos1));
		pos1 = pos2 + 1;
		pos2 = a.find(c, pos1);
	}
	if (pos1 != a.size())
	{
		v.push_back(a.substr(pos1, a.size() - pos1));
	}

}

int main()
{
	map<char, int> tanzhu;
	map<char, int> xiaohong;
	string t, x;
	cin >> t >> x;
	int cnttan = 0, cnthong = 0;
	for (int i = 0; i < t.size(); i++)
	{
		if (tanzhu.find(t[i]) == tanzhu.end())
		{
			tanzhu.insert(make_pair(t[i], 1));
		}
		else
		{
			tanzhu.find(t[i])->second++;
		}

	}
	for (int i = 0; i < x.size(); i++)
	{
		if (xiaohong.find(x[i]) == xiaohong.end())
		{
			xiaohong.insert(make_pair(x[i], 1));
		}
		else
		{
			xiaohong.find(x[i])->second++;
		}
	}
	int duo = 0, shao = 0;
	int flag = 0;//代表小红所需的珠子小于等于摊主提供的珠子
	for (map<char, int>::iterator it = xiaohong.begin(); it != xiaohong.end(); it++)
	{
		if (tanzhu.find(it->first) == tanzhu.end())
		{
			flag = 1;
			shao += it->second;
			continue;
		}
		else
		{
			if (tanzhu.find(it->first)->second < it->second)
			{
				flag = 1;
				shao += it->second - tanzhu.find(it->first)->second;
				continue;
			}
		}
	}
	for (map<char, int>::iterator it = xiaohong.begin(); it != xiaohong.end(); it++)
	{
		cnthong += it->second;
	}
	for (map<char, int>::iterator it = tanzhu.begin(); it != tanzhu.end(); it++)
	{
		cnttan += it->second;
	}
	if (flag == 1)
	{
		cout << "No " << shao;
	}
	else
	{
		cout << "Yes " << cnttan - cnthong;
	}
	return 0;
}

1041 考试座位号

#include <iostream>
#include<string>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	map<int, pair<int, string> > stu;
	while (n--)
	{
		string id;
		int test, exam;
		cin >> id >> test >> exam;
		pair<int, string> tmp = make_pair(exam, id);
		stu.insert(map<int, pair<int, string>>::value_type(test, tmp));
		//pair<int, pair<int, int> > t;
		//map的用法:https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html
	}
	int m;
	cin >> m;
	while (m--)
	{
		int test;
		cin >> test;
		map<int,pair<int,string> >::iterator it = stu.find(test);
		pair<int, string> tmp = it->second;
		cout << tmp.second << " " << tmp.first << endl;
	}
	return 0;
}

1042 字符统计

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

//https://www.cnblogs.com/balingybj/p/4678850.html 
//string中,使用algorithm中的transform函数进行大小写转换,toupper,tolower

void split(string a, vector<string>& v, char c)
{
	int pos1 = 0, pos2 = 0;
	pos2 = a.find(c, 0);
	while (pos2 != string::npos)
	{
		v.push_back(a.substr(pos1, pos2 - pos1));
		pos1 = pos2 + 1;
		pos2 = a.find(c, pos1);
	}
	if (pos1 != a.size())
	{
		v.push_back(a.substr(pos1, a.size() - pos1));
	}

}

int main()
{
	string line;
	getline(cin, line);
	map<char, int> str;
	for (int i = 0; i < line.size(); i++)
	{
		if (line[i] >= 'a' && line[i] <= 'z')
		{
			if (str.find(line[i]) == str.end())
			{
				str.insert(make_pair(line[i], 1));
			}
			else
			{
				str.find(line[i])->second++;
			}
		}
		if (line[i] >= 'A' && line[i] <= 'Z')
		{
			char temp = 'a' + (line[i] - 'A');
			if (str.find(temp) == str.end())
			{
				str.insert(make_pair(temp, 1));
			}
			else
			{
				str.find(temp)->second++;
			}
		}
	}
	int maxl = 0;
	char ch;
	for (map<char, int>::reverse_iterator rit = str.rbegin(); rit != str.rend(); rit++)
	{
		//cout << it->first << " " << it->second << endl;
		if (rit->second >= maxl)
		{
			ch = rit->first;
			maxl = rit->second;
		}
	}
	cout << ch << " " << maxl;
	return 0;
}

1043 输出PATest

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

//https://www.cnblogs.com/balingybj/p/4678850.html 
//string中,使用algorithm中的transform函数进行大小写转换,toupper,tolower

void split(string a, vector<string>& v, char c)
{
	int pos1 = 0, pos2 = 0;
	pos2 = a.find(c, 0);
	while (pos2 != string::npos)
	{
		v.push_back(a.substr(pos1, pos2 - pos1));
		pos1 = pos2 + 1;
		pos2 = a.find(c, pos1);
	}
	if (pos1 != a.size())
	{
		v.push_back(a.substr(pos1, a.size() - pos1));
	}

}

int main()
{
	vector<char> a(6,0);//顺序0-5,分别是P A T e s t

	string str;//所有输入是字符串的题目,都需要考虑字符串中包不包括空格,如果包括的话就需要用getline而不是cin
	cin>>str;
    int sum=0;
    char letter[6]={'P','A','T','e','s','t'};
	for (int i = 0; i < str.size(); i++)
	{
        for(int j=0;j<6;j++)
        {
            if(str[i]==letter[j])
            {
                a[j]++;
                sum++;
                continue;
            }
        }
	}
	while (sum)
	{
        for(int i=0;i<6;i++)
        {
            if(a[i])//这里如果写a[i]>0,最后一个用例点死活过不去,写成a[i]就可以了……为什么呢????
            {
                cout<<letter[i];
                a[i]--;
                sum--;
            }
        }
	}
	return 0;
}

1046 划拳

#include <iostream>
#include<string>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int cnta = 0, cntb = 0;
	while (n--) {
		int a1, a2, b1, b2;
		cin >> a1 >> a2 >> b1 >> b2;
		int flaga = 0, flagb = 0;
		if (a1 + b1 == a2) flaga = 1;
		if (a1 + b1 == b2) flagb = 1;
		if (flaga == 0 && flagb == 1) cnta++;
		if (flaga == 1 && flagb == 0) cntb++;
	}
	cout << cnta << " " << cntb;
	return 0;
}

1047 编程团体赛

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

//https://www.cnblogs.com/balingybj/p/4678850.html 
//string中,使用algorithm中的transform函数进行大小写转换,toupper,tolower

void split(string a, vector<string>& v, char c)
{
	int pos1 = 0, pos2 = 0;
	pos2 = a.find(c, 0);
	while (pos2 != string::npos)
	{
		v.push_back(a.substr(pos1, pos2 - pos1));
		pos1 = pos2 + 1;
		pos2 = a.find(c, pos1);
	}
	if (pos1 != a.size())
	{
		v.push_back(a.substr(pos1, a.size() - pos1));
	}

}

int main()
{
	int n;
	cin >> n;
	map<int, int> team;
	while (n--)
	{
		string a;
		int b;
		cin >> a >> b;
		int pos = a.find("-");
		int tid = atoi(a.substr(0, pos).c_str());
		int pid = atoi(a.substr(pos+1, a.size()-pos-1).c_str());
		if (team.find(tid) == team.end())
		{
			team.insert(make_pair(tid, b));
		}
		else
		{
			team.find(tid)->second += b;
		}
	}
	int maxg=0, tid=0;
	for (map<int, int>::iterator it = team.begin(); it != team.end(); it++)
	{
		if (it->second > maxg)
		{
			maxg = it->second;
			tid = it->first;
		}
	}
	cout << tid << " " << maxg;
	return 0;
}

1056 组合数的和

#include <iostream>
#include<string>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int* a = new int[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (j == i) continue;
			sum += 10 * a[i] + a[j];
		}
	}
	cout << sum;
	return 0;
}

1057 数零壹

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

//https://www.cnblogs.com/balingybj/p/4678850.html 
//string中,使用algorithm中的transform函数进行大小写转换,toupper,tolower

void split(string a, vector<string>& v, char c)
{
	int pos1 = 0, pos2 = 0;
	pos2 = a.find(c, 0);
	while (pos2 != string::npos)
	{
		v.push_back(a.substr(pos1, pos2 - pos1));
		pos1 = pos2 + 1;
		pos2 = a.find(c, pos1);
	}
	if (pos1 != a.size())
	{
		v.push_back(a.substr(pos1, a.size() - pos1));
	}

}

int main()
{
	string str;
	getline(cin, str);
	int sum = 0;
	for (int i = 0; i < str.size(); i++)
	{
		if (str[i] >= 'a' && str[i] <= 'z')
		{
			sum += str[i] - 'a';
			sum += 1;
			//cout << str[i] - 'a' << endl;
		}
		else if (str[i] >= 'A' && str[i] <= 'Z')
		{
			sum += str[i] - 'A';
			sum += 1;
			//cout << str[i] - 'A' << endl;
		}
	}
	int cnt0 = 0, cnt1 = 0;
	//cout << sum << endl;
	while (sum)
	{
		int yu = sum % 2;
		//cout << yu;
		sum /= 2;
		if (yu == 0) cnt0++;
		else cnt1++;
	}
	cout << cnt0 << " " << cnt1;
	return 0;
}

1061 判断题

#include <iostream>
#include<string>
#include<map>
#include<iomanip>
#include<math.h>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int *weight = new int[m];
	for (int i = 0; i < m; i++)
		cin >> weight[i];
	int* ans = new int[m];
	for (int i = 0; i < m; i++)
		cin >> ans[i];
	int* stu = new int[m];
	while (n--) {
		int score = 0;
		for (int i = 0; i < m; i++)
		{
			cin >> stu[i];
			if (stu[i] == ans[i])
				score += weight[i];
		}
		cout << score << endl;

	}
	delete weight;
	delete ans;
	delete stu;
	return 0;
}

1063 计算谱半径

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

//https://www.cnblogs.com/balingybj/p/4678850.html 
//string中,使用algorithm中的transform函数进行大小写转换,toupper,tolower

int main()
{
	int n;
	cin >> n;
	float ans = -1.0;
	while (n--)
	{
		float a, b;
		cin >> a >> b;
		float t = sqrt(a * a + b * b);
		t = t * 100 + 0.5; //4.1234567 * 100 = 412.34567   //+0.5 412.84567 //int()413 
		int x = t;//round(t);
		float tt = (x * 1.0) / 100;
		if (tt >= ans)
		{
			ans = tt;
		}
	}
	//cout << ans << endl;
	printf("%0.2f", ans); //需要考虑当ans的精度不足2位时,还是按照保留两位精度输出

	return 0;
}

1064 朋友数

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

//https://www.cnblogs.com/balingybj/p/4678850.html 
//string中,使用algorithm中的transform函数进行大小写转换,toupper,tolower

void split(string a, vector<string>& v, char c)
{
	int pos1 = 0, pos2 = 0;
	pos2 = a.find(c, 0);
	while (pos2 != string::npos)
	{
		v.push_back(a.substr(pos1, pos2 - pos1));
		pos1 = pos2 + 1;
		pos2 = a.find(c, pos1);
	}
	if (pos1 != a.size())
	{
		v.push_back(a.substr(pos1, a.size() - pos1));
	}

}

int main()
{
	int n;
	cin >> n;
	vector<int> ans;
	while (n--)
	{
		string t;
		cin >> t;
		int sum = 0;
		for (int i = 0; i < t.size(); i++)
		{
			sum += t[i] - '0';
		}
		if (ans.empty())
		{
			ans.push_back(sum);
		}
		else {
			int flag = 0;
			for (int i = 0; i < ans.size(); i++)
			{
				if (ans[i] == sum)
				{
					flag = 1;
					break;
				}
			}
			if (flag == 0)
			{
				ans.push_back(sum);
			}
		}
	}
	cout << ans.size() << endl;
	sort(ans.begin(), ans.end());
	for (int i = 0; i < ans.size()-1; i++)
		cout << ans[i] << " ";
    cout<<ans[ans.size()-1];
	return 0;
}

1066 图像过滤

#include <iostream>
#include<string>
#include<map>
#include<iomanip>
#include<math.h>
#include<vector>
using namespace std;

int main()
{
	int n, m, pa, pb, grey;
	cin >> n >> m >> pa >> pb >> grey;
	vector<vector<int> > map;
	map.resize(n);
	for (int i = 0; i < n; i++)
		map[i].resize(m);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> map[i][j];
			if (map[i][j] >= pa && map[i][j] <= pb)
				map[i][j] = grey;
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++) {
			if (j < m - 1) printf("%03d ", map[i][j]);
			else printf("%03d", map[i][j]);
		}
		if(i<n-1) cout << endl;
	}
	
	return 0;
}

1067 试密码

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
int main()
{
	string ans;
	int n;
	cin >> ans >> n;
	getchar();//吃掉回车
	string input;
	getline(cin, input);
	int cnt = 0;
	int nn = n;
	while (nn--)
	{
		if (input == "#")
		{
			return 0;
		}
		if (input == ans)
		{
			cout << "Welcome in";
			return 0;
		}
		else
		{
			cout << "Wrong password: " << input << endl;
			cnt++;
			if (cnt >= n)
			{
				cout << "Account locked" << endl;
				return 0;
			}
			getline(cin, input);
		}
	}
	cout << "Account locked" << endl;
	return 0;
}

1069 微博转发抽奖

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

struct person
{
	string name;
	int flag = 0;//代表没有中过奖,如果中过了,修改为1
	person(string nname, int nflag)
	{
		name = nname;
		flag = nflag;
	}
};

void split(string a, vector<string>& v, char c)
{
	int pos1 = 0, pos2 = 0;
	pos2 = a.find(c, 0);
	while (pos2 != string::npos)
	{
		v.push_back(a.substr(pos1, pos2 - pos1));
		pos1 = pos2 + 1;
		pos2 = a.find(c, pos1);
	}
	if (pos1 != a.size())
	{
		v.push_back(a.substr(pos1, a.size() - pos1));
	}

}

int main()
{
	int m, n, s;
	cin >> m >> n >> s;
	vector<person> v;
	int temp = m;
	while (temp--)
	{
		string t;
		cin >> t;
		v.push_back(person(t, 0));
	}
	if (s > m)
	{
		cout << "Keep going...";
	}
	else
	{
		int cnt = 0;
		cout << v[s - 1].name << endl;
		for (int j = 0; j < v.size(); j++)
		{
			if (v[j].name == v[s-1].name)
			{
				v[j].flag = 1;
			}
		}
		for (int i = s ; i < m; i++)
		{
			cnt++;
			if (cnt == n)
			{
				if (v[i].flag == 0)
				{
					cout << v[i].name << endl;
					for (int j = 0; j < v.size(); j++)
					{
						if (v[j].name == v[i].name)
						{
							v[j].flag = 1;
						}
					}
					cnt = 0;
				}
				else
				{
					cnt -= 1;
				}
			}
		}
	}
	return 0;
}

1071 小赌怡情

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
    int total, time;
    cin >> total >> time;
    while (time--) {
        int n1, n2, b, t;
        cin >> n1 >> b >> t >> n2;
        int ans = 0;
        if (n1 < n2)
            ans = 1;
       
        if (t > total) {
            cout << "Not enough tokens.  Total = " << total << "." << endl;
            continue;
        }
        if (b == ans) {
            total += t;
            cout << "Win " << t << "!  Total = " << total << "." << endl;
        }
        else
        {
            total -= t;
            cout << "Lose " << t << ".  Total = " << total << "." << endl;
        } 
        if (total <= 0) {
            cout << "Game Over." << endl;
            break;
        }
    }
    return 0;
}
//我草泥马!!!!!!!!!!!!!居然是因为game over的o没有大写而wa了好多好多好多次,看了半个小时也没找到错误我艹

1076 Wifi密码

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string ans = "";
    while (n--) {
        char x = 'A';
        string t;
        for (int i = 0; i < 4; i++) {
            cin >> t;
            if (t[2] == 'T') {
                x = t[0];
            }
        }
        ans += x;
    }
    for (int i = 0; i < ans.length(); i++) {
        cout << ans[i] - 'A' + 1;
    }
    return 0;
}

1081 检查密码

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
    //来自网上:可能的坑点,一行当中存在空格,不能用cin >> string的方式,用getline一次输入一行即可
    //exo me??什么叫做一行当中存在空格?????这不是用户密码吗???为什么输入的一行密码中会存在空格?啊?好的吧我明白了
    int n;
    cin >> n;
    getchar();
    getchar();
    getchar();
    getchar();
    getchar();
    string pwd;
    while (n--) {
        getline(cin, pwd);
        //cin >> pwd;
        if (pwd.length() < 6) {
            cout << "Your password is tai duan le." << endl;
            continue;
        }
        int has_num = 0;
        int has_letter = 0;
        int has_dot = 0;
        int has_luan = 0;
        for (int i = 0; i < pwd.length(); i++) {
            if (pwd[i] >= 'A' && pwd[i] <= 'Z' || pwd[i] >= 'a' && pwd[i] <= 'z') {
                has_letter += 1;
                continue;
            }
            if (pwd[i] >= '0' && pwd[i] <= '9') {
                has_num += 1;
                continue;
            }
            if (pwd[i] == '.') {
                has_dot += 1;
                continue;
            }
            has_luan += 1;
            
        }
        //cout << has_dot;
        if (has_luan >0) {
            cout << "Your password is tai luan le." << endl;
            continue;
        }
        if (has_letter > 0 && has_num == 0) {
            cout << "Your password needs shu zi." << endl;
            continue;
        }
		if (has_letter == 0 && has_num > 0) {
            cout << "Your password needs zi mu." << endl;
            continue;
        }
        if (has_letter == 0 && has_num == 0 &&has_dot>0) {
            cout << "Your password needs zi mu." << endl;
            cout << "Your password needs shu zi." << endl;

            continue;
        }
        cout << "Your password is wan mei." << endl;
    }
    return 0;
}

1086 就不告诉你

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int an = a * b;
    string ans = to_string(an);
    int len = ans.length();
    /*for (int i = 0; i <len/2+1; i++) {
        char tmp = ans[i];
        ans[i] = ans[len - i - 1];
        ans[len - i - 1] = tmp;
    }*/
    int flag = 1;
    for (int i = len - 1; i >= 0; i--)
    {
        if (flag == 1 && ans[i] == '0') {
            continue;
        }
        flag = 0;
        cout << ans[i];
    }
    return 0;
}

1088 三人行

	#include<iostream>
	#include<iomanip>
	#include<math.h>
	#include<string>
	#include<algorithm>
	#include<map>
	#include<vector>
	using namespace std;


//死活过不了第4个测试点,它应该是考虑了丙为double,因此要把相关的都改成double,比如丙是1.2,1.2*5=6,所以乙还是可以是正整数
	string check(double me, double a)
	{
		if (me == a)
			return "Ping";
		if (me > a)
			return "Gai";
		return "Cong";
	}

	int main()
	{
		int me, x, y;
		cin >> me >> x >> y;
		double jia, yi, bing;
		int flag = 0;
		for (int i = 99; i >= 10; i--)
		{
            int t=i/10+10*(i%10);
            double tt = abs(t - i) * 1.0 / x;
			if (tt == t * 1.0 / y) {
				jia = i;
				yi = t;
				bing = tt;
				flag = 1;
				break;
			}
		}
		if (flag == 0)
		{
			cout << "No Solution";
		}
		else
		{
			cout << jia << " ";
			cout << check(me, jia) << " " << check(me, yi) << " " << check(me, bing);
		}
		return 0;
	}

1091 N-自守数

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
    int m;
    cin >> m;
    while (m--) {
        int ans_n = 0;
        int k;
        cin >> k;
        if (k == 0) {
            cout << "1 0" << endl;
            continue;
        }
        
        if (k == 1) {
            cout << "1 1" << endl;
            continue;
        }
        int kk = k * k;
        string strk = to_string(k);
        int len = strk.size();
        for (int i = 1; i <= 9; i++) {
            int tmp = i * kk;
            string t = to_string(tmp);
            int cnt_k = len ;
            int flag = 0;
            for (int j = t.length() - 1; j >= t.length() - len; j--)
            {
                cnt_k--;
                if (t[j] != strk[cnt_k])
                {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0) {
                ans_n = i;
                cout << ans_n << " " << tmp << endl;
                break;
            }

        }

        if (ans_n == 0) {
            cout << "No" << endl;
        }
    }
    return 0;
}

1092 最好吃的月饼

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int m1 = m;
	map<int, int> ans;
	while (m1--)
	{
		for (int i = 1; i <= n; i++)
		{
			int temp;
			cin >> temp;
			if (ans.find(i) != ans.end())
			{
				ans.find(i)->second += temp;
			}
			else
			{
				ans.insert(make_pair(i, temp));
			}
		}
	}
	int max = 0;
	//vector<int> pos;
	for (map<int, int>::iterator it = ans.begin(); it != ans.end(); it++)
	{
		if (it->second >= max)
		{
			max = it->second;
		}
		//cout << it->first << " " << it->second << endl;
	}
	int cnt = 0;
	for (map<int, int>::iterator it = ans.begin(); it != ans.end(); it++)
	{
		if (it->second == max)
		{
			cnt++;
		}
		//cout << it->first << " " << it->second << endl;
	}
	int cnt1 = 0;
	cout << max << endl;
	for (map<int, int>::iterator it = ans.begin(); it != ans.end(); it++)
	{
		if (it->second == max)
		{
			cout << it->first;
			cnt1++;
			if (cnt1 != cnt)
			{
				cout << " ";
			}
		}
		//cout << it->first << " " << it->second << endl;
	}
	return 0;
}

1093 字符串A+B

#include<iostream>
#include<iomanip>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int cmp(pair<char, int>& a, pair<char, int>& b)
{
	return a.second < b.second;
}
void sortMap(vector<pair<char, int> >& v, map<char, int>& m)
{
	for (map<char, int>::iterator it = m.begin(); it != m.end(); it++)
	{
		v.push_back(*it);
	}
	sort(v.begin(), v.end(), cmp);
}

int main()
{
	string line1, line2;
	map<int, int> m1;
	map<int, int> m2;
	getline(cin, line1);
	getline(cin, line2);
	map<char, int> ans;
	int cnt = 0;
	for (int i = 0; i < line1.size(); i++)
	{
		//int temp = int(line1[i]);
		if (ans.find(line1[i]) == ans.end())
		{
			//cout << line1[i] << " ";
			ans.insert(make_pair(line1[i], cnt));
			cnt++;
		}
	}
	//cout << endl;
	for (int i = 0; i < line2.size(); i++)
	{
		//int temp = int(line2[i]);
		if (ans.find(line2[i]) == ans.end())
		{
			//cout << line2[i] << " ";
			ans.insert(make_pair(line2[i], cnt));
			cnt++;
		}
	}
	//cout << endl;

	vector<pair<char, int> > v;
	sortMap(v, ans);
	//for (map<char, int>::iterator it = ans.begin(); it != ans.end(); it++)
	//{
	//	cout << it->first << " " << it->second;
	//}
	for (int i = 0; i < v.size(); i++)
	{
		cout << v[i].first;
	}
	return 0;
}

废话

去年保研时,我因为机试太垃圾而失去了一个很好的机会,导致最后只能远走他乡去了别的学校。这件事给了我很大的打击,也让我真正认清了自己的基础有多糟糕。我本打算利用保研后的空闲时间好好刷题,但是显然我太不自律,所以那段时间还是在混吃等死。

毕设我做的也是一堆垃圾,这几天毕设快要答辩了,即将成为研究生的我也终于开始正视自己能力极差这个问题。所以我打算写个博客记录自己的刷题经历,预想的路线是pat乙——pat甲——leetcode(简单和中级)。希望能够好好补一下自己的基础,为两年半后的实习和校招做准备。

祝所有人都有个光明的前程。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值