1093 字符串A+B (20 分)


//1093 字符串A+B (20 分)
#include<bits/stdc++.h>
using namespace std;

int main(){
   
    ios::sync_with_stdio(0);
    string s1, s2, s;
    int hash[200] = {
   0};
    getline(cin, s1);
    getline(cin, s2);
    s = s1 + s2;
    //哈希去重
    for (int i = 0; i < s.size();i++){
   
        if(hash[s[i]]==0)
            cout << s[i];
        hash[s[i]] = 1;
    }
    return 0;
}

1095 解码PAT准考证 (25 分)


#include<bits/stdc++.h>
using namespace std;
//1095 解码PAT准考证 (25 分)
struct node{
   
    string t;
    int value;
};
bool cmp(const node &a,const node &b){
   
    return a.value != b.value ? a.value > b.value : a.t < b.t;
}

int main(){
   
    ios::sync_with_stdio(0);
    int n, k, num;
    string s;
    cin >> n >> k;
    vector<node> v(n);
    for (int i = 0; i < n;i++)
        cin >> v[i].t >> v[i].value;
    for (int i = 1; i <= k; i++)
    {
   
        cin >> num >> s;
        printf("Case %d: %d %s\n", i, num, s.c_str());
        vector<node> ans;
        int cnt = 0;
        int sum = 0;
        if (num == 1)
        {
   
            for (int j = 0; j < n; j++)
            {
   
                if (v[j].t[0] == s[0])
                    ans.push_back(v[j]);
            }
        }
        else if (num == 2)
        {
   
            for (int j = 0; j < n; j++)
            {
   
                if (v[j].t.substr(1, 3) == s)
                {
   
                    cnt++;
                    sum += v[j].value;
                }
            }
            if (cnt != 0)
                printf("%d %d\n", cnt, sum);
        }
        else if (num == 3)
        {
   
            unordered_map<string, int> m;
            for (int j = 0; j < n; j++)
            {
   
                if (v[j].t.substr(4, 6) == s)
                    m[v[j].t.substr(1, 3)]++;
            }
            for (auto it : m)
                ans.push_back({
   it.first, it.second});
        }
        sort(ans.begin(), ans.end(), cmp);
        for (int j = 0; j < ans.size(); j++)
            printf("%s %d\n", ans[j].t.c_str(), ans[j].value);
        if (((num == 1 || num == 3) && ans.size() == 0) || (num == 2 && cnt == 0))
            printf("NA\n");
    }
    return 0;
}

1086 就不告诉你 (15 分)


#include<bits/stdc++.h>
using namespace std;
//1086 就不告诉你 (15 分)
int main(){
   
    ios::sync_with_stdio(0);
    int a, b;
    cin>>a>>b;
    int c = a * b;
    int arr[100]={
   0};
    int i = 0;
    while(c){
   
        arr[i++] = c % 10;
        c /= 10;
    }
    int flag=1;
    for (int j = 0; j <i;j++){
   
        if(arr[j]==0&&flag)//前导零
            continue;
        cout << arr[j];
        flag=0;
    }
        return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   
    int a,b;
    cin>>a>>b;
    string t=to_string(a*b);
    reverse(t.begin(),t.end());//反转
    b=0;
    a=t.length();
    while(t[b]=='0'&&b<t.length() - 1) b++;//去前导零
    for(int i=b;t[i];i++) cout<<t[i];
    return 0;
}

1081 检查密码 (15 分)


#include<bits/stdc++.h>
using namespace std;
//1081 检查密码 (15 分)
int main(){
   
	int t;
	cin>>t;getchar();//读回车 
	while(t--){
   
		string s;
		getline(cin,s);
		if(s.length()>=6){
   
			int a=0,b=0,c=0;
			for(int j=0;j<s.length();j++){
   
				if(s[j]!='.'&&!isalnum(s[j]))
                    a = 1;
                else if(isalpha(s[j]))
                    b = 1;
                else if(isdigit(s[j]))
                    c = 1;
            }
            if(a==1)
                cout << "Your password is tai luan le.\n";
            else if(c==0)
                cout << "Your password needs shu zi.\n";
            else if(b==0)
                cout << "Your password needs zi mu.\n";
            else
                cout << "Your password is wan mei.\n";
        }else{
   
            cout << "Your password is ***an le.\n";
        }
	}
	return 0;
}

1029 旧键盘 (20 分)


#include<bits/stdc++.h>
using namespace std;
//1029 旧键盘 (20 分)
int main(){
   
    ios::sync_with_stdio(0);
    string s1, s2;
    cin >> s1;
    cin >> s2;
    int hash[100] = {
   0};
    for (int i = 0; i < s1.length(); i++) {
   
        s1[i] = toupper(s1[i]);//小写转大写;
    }
    for (int i = 0; i < s2.length(); i++) {
   
        s2[i] = toupper(s2[i]);
    }
    for (int i = 0; i < s1.length(); i++) {
   
        int j;
        for (j = 0; j < s2.length(); j++) {
   
            if (s1[i] == s2[j]) {
   
                break;
            }
        }
        if (j == s2.length() && hash[s1[i]]==0) {
   
            cout << s1[i];
            hash[s1[i]] = 1;
        }
    }
        return 0;
}