排序(一)

1001. A+B Format (20)-PAT甲级真题

#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int sum=a+b;
	if(sum<0)
	{
		cout<<"-";
		sum=-sum;
	}
	string s=to_string(sum);//用to_string函数把数字转换成字符串
	string res;
	int k=0;
	for(int i=s.length()-1;i>=0;i--)
	{//从后往前数 
		res=s[i]+res;
		k++;
		if(k%3==0&&i!=0)res=","+res;
	 } 
	 cout<<res<<endl;
	 return 0;
 } 

1005. Spell It Right (20)-PAT甲级真题

#include<iostream>
using namespace std;
const int maxn=10010;
int a[maxn];
int main()
{
	string str[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
	string s;
	cin>>s;
	int sum=0;
	for(int i=0;i<s.length();i++)
	{
		sum+=s[i]-'0';
	}
	string st=to_string(sum);
	cout<<str[st[0]-'0'];
	for(int i=1;i<st.length();i++)cout<<" "<<str[st[i]-'0'];
	return 0;
}

1006. Sign In and Sign Out (25)-PAT甲级真题

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string flag_begin="24:00:00";
	string flag_end="00:00:00";
	string begin_num,end_num;
	for(int i=0;i<n;i++)
	{
		string number,begin,end;
		cin>>number>>begin>>end;
		if(begin<flag_begin)
		{
			flag_begin=begin;
			begin_num=number;
		}
		if(end>flag_end)
		{
			flag_end=end;
			end_num=number;
		}
	}
	cout<<begin_num<<" "<<end_num<<endl;
	return 0;
}

1035. Password (20)-PAT甲级真题

#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<string>v;
	for(int i=0;i<n;i++)
	{
		string name,p;//输入用户名和密码 
		cin>>name>>p;
		int len=p.length();
		int flag=0;
		for(int j=0;j<len;j++)
		{
			switch(p[j])
			{
				case '1' : p[j] = '@'; flag = 1; break;//数字1 
                case '0' : p[j] = '%'; flag = 1; break;//数字0 
                case 'l' : p[j] = 'L'; flag = 1; break;//小写L 
                case 'O' : p[j] = 'o'; flag = 1; break;//大写O 
			}
		}
		if(flag) //有需要修改的密码 
		{
            string temp = name + " " + p;
            v.push_back(temp);//加入到vector数组中 
        }
	}
	int cnt = v.size();
    if(cnt != 0) //输出需要修改的密码 
	{
        printf("%d\n", cnt);//输出个数 
        for(int i = 0; i < cnt; i++)
            cout << v[i] << endl;
    } 
	else if(n == 1) 
	{
        printf("There is 1 account and no account is modified");
    } 
	else//没有需要修改的密码 
	 {
        printf("There are %d accounts and no account is modified", n);
    }
	return 0;
}

1036. Boys vs Girls (25)-PAT甲级真题 

#include <iostream>
using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    string female, male;
    int femalescore = -1, malescore = 101;
    for(int i = 0; i < n; i++) 
    {
        string name, sex, num;
        int score;
        cin >> name >> sex >> num;
        scanf("%d", &score);
        if(sex == "F") {
            if(femalescore < score) {
                femalescore = score;
                female = name + " " + num;
            }
        } else if(malescore > score) {
                malescore = score;
                male = name + " " + num;
            }
    }
    if(femalescore != -1)
        cout << female << endl;
    else
        printf("Absent\n");
    if(malescore != 101)
        cout << male << endl;
    else
        printf("Absent\n");
    if(femalescore != -1 && malescore != 101)
        printf("%d", femalescore - malescore);
    else
        printf("NA");
    return 0;
}

1050. String Subtraction (20)-PAT甲级真题(哈希) 

#include <iostream>
#include <string.h>
using namespace std;
char s1[100000], s2[100000];
int main() 
{
    cin.getline(s1, 100000);//输入一整行字符串 
    cin.getline(s2, 100000);
    int lens1 = strlen(s1), lens2 = strlen(s2);
    bool flag[256] = {false};//使用哈希 
    for(int i = 0; i < lens2; i++)
        flag[s2[i]] = true;
    for(int i = 0; i < lens1; i++) 
	{
        if(!flag[s1[i]])
            printf("%c", s1[i]);
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值