2020年PAT七月前复习备注

PAT 2020年 @author 江左


2020pat春季乙级 99分过的,没有满分,有点遗憾,等会上传有瑕疵的我的考试代码。

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

备注:无。

#include<bits/stdc++.h>
using namespace std;
int main() {
    int cnt=0,n;cin>>n;
    while(n!=1){
        if(n%2==0) n/=2;
        else n=(3*n+1)/2;
        cnt++;
    }
    cout<<cnt;
}
1002 写出这个数 (20分)

备注:字符数字减去‘0’,可以比较简单的得到数字本身

#include<iostream>
#include<string>
using namespace std;
int main() {
	string input; cin >> input;
	int sum = 0;
	int len = input.length();
	for (int i = 0; i < len; i++)
		sum += (input[i] - '0');
	string result = to_string(sum);
	int len2 = result.length();
	for (int i = 0; i < len2; i++)
	{
		if (i != 0)
			cout << " ";
		char ch = result[i]; string s="";
		switch (ch) {
		case '1':s = "yi"; break;
		case '2':s = "er"; break;
		case '3':s = "san"; break;
		case '4':s = "si"; break;
		case '5':s = "wu"; break;
		case '6':s = "liu"; break;
		case '7':s = "qi"; break;
		case '8':s = "ba"; break;
		case '9':s = "jiu"; break;
		case '0':s = "ling"; break;
		}
		cout << s;
	}
}
1004 成绩排名 (20分)

备注:最基本的sort()使用,即用特定容器存住排序对象,自定义排序规则cmp,调用即可。备注sort()在algorithm里面。

#include<bits/stdc++.h>
using namespace std;
class stu{
public:
    string name,id;int score;
};
bool cmp(stu a,stu b){
    return a.score>b.score;
}
int main() {
    int n;cin>>n;vector<stu>v;
    v.resize(n);
    for(int i=0;i<n;i++){
       cin>>v[i].name>>v[i].id>>v[i].score; 
    }
    sort(v.begin(),v.end(),cmp);
    cout<<v[0].name<<" "<<v[0].id<<endl;
    cout<<v[n-1].name<<" "<<v[n-1].id<<endl;
}
1005 继续(3n+1)猜想 (25分)

备注:把每个数字覆盖的值都标记一下,从大到小排序后,看
自己有没有被别人标记,没有标记就输出。
加粗那一行挺重要的,能加快算法速率,但是这题没有考这么细。

#include<bits/stdc++.h>
using namespace std;
int arr[10000]={0};
int main() {
    int n;cin>>n;vector<int> v;
    for(int i=0;i<n;i++){
        int temp;cin>>temp;
        v.push_back(temp);
        
        **if(arr[temp]==1) continue;**
        
        while(temp!=1){
            if(temp%2==0) temp/=2;
            else temp=(3*temp+1)/2;
            arr[temp]=1;
        }
    }
    sort(v.begin(),v.end(),greater<int>());
    bool f=false;
    for(int i=0;i<v.size();i++){
        if(arr[v[i]]==0){
            if(f) cout<<" ";
             cout<<v[i];f=true;
        }    
    }
}
1006 换个格式输出整数 (15分)

备注:变量记得初始化。(第6行)

#include<bits/stdc++.h>
using namespace std;
int main() {
    string in;cin>>in;
    int len=in.length();
    int bNum=0,sNum=0,gewei=0;  
    if(len==3){
        bNum=in[0]-'0';
        sNum=in[1]-'0';
        gewei=in[2]-'0';
    }else if(len==2){
        sNum=in[0]-'0';
        gewei=in[1]-'0';
    }else
        gewei=in[0]-'0';
    
    for(int i=0;i<bNum;i++)
        cout<<'B';
    for(int i=0;i<sNum;i++)
        cout<<'S';
    for(int i=0;i<gewei;i++)
        cout<<i+1;
}
1007 素数对猜想 (20分)

备注:用一个变量记录当前变量的前一个素数。

#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n){
    for(int i=2;i<int(sqrt(n)+1);i++){
		if(n%i==0) return false;
    }
    return true;   
}
int main() {
	int num;cin >> num;
	int counts = 0,lastZhiShu = 3;
	for (int i = 3; i <= num; i++) {
		if (isPrime(i)) {
			if (i - lastZhiShu == 2) 
				counts++;
			lastZhiShu = i;
		}
	}
	cout << counts << endl;
    return 0;
}
1008 数组元素循环右移问题 (20分)

备注: 无

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;cin>>n>>m;
    int *arr=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int t=m%n;//排除多次轮回后的移动次数
    for(int i=n-t;i<n;i++)
        cout<<arr[i]<<" ";
    for(int i=0;i<n-t;i++){
        cout<<arr[i];
        if(i!=n-t-1) cout<<" ";
    }
}
1009 说反话 (20分)

备注:用了while(cin>>)的手法,读入未知数量的输入
利用栈的特性,先进后出,后进先出。

#include<bits/stdc++.h>
using namespace std;
int main() {
	stack<string> s;string in;
	while (cin >> in) 
		s.push(in);
	while (!s.empty()) {
		cout << s.top(); s.pop();
		if (!s.empty()) cout << " ";
	}
}
1010 一元多项式求导 (25分)

备注: 无

#include <iostream>
using namespace std;
int main() {
	int a, b, flag = 0;
	while (cin >> a >> b) {
		if (b != 0) {
			if (flag == 1) cout << " ";
			cout << a * b << " " << b - 1;
			flag = 1;
		}
	}
	if (flag == 0) cout << "0 0";
	return 0;
}
1011 A+B 和 C (15分)

备注: 这是一种极为投机取巧的写法。long double精度很高。
真正的大数字比较我没细想,估计在比较符号后,先比较小数点前有效位数,在从最高位开始比较这个样子。
在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		long double a, b, c; cin >> a >> b >> c;
		string flag = a + b > c ? "true" : "false";
		cout << "Case #" << i + 1 << ": " << flag << endl;
	}
}
1012 数字分类 (20分)

备注: 无

#include<bits/stdc++.h>
using namespace std;
int main() {
	vector<int> v0,v1,v2,v3,v4;
    v0[0]=0;v1[0]=0;v3[0]=0;int num3=0;
    int max=-1;
    int temp;int i=1;
    while(cin>>temp){
        i++;
        int yushu=temp%5;
        if(yushu==0){
            v0[0]+=temp;
        }else if(yushu==1){
            v1[0]+=pow(-1,i+1)*temp;
        }else if(yushu==2){
            v2.push_back(temp);
        }else if(yushu==3){
            num3++;v3[0]+=temp;
        }else{
           max=max<temp?temp:max; 
        }
    }
}
1013 数素数 (20分)

备注: 无

#include<iostream>
#include<math.h>
using namespace std;
bool isPri(int n) {
	for (int i = 2; i <= sqrt(n); i++)
	{
		if (n%i == 0)
			return false;
	}
	return true;
}
int main()
{
	int M, N; int counts = 0;
	scanf("%d %d", &M, &N);
	int p = 0; int begin = 2;
	while (true) {
		if (isPri(begin))
		{
			p++; 
			if (p >= M)
			{
				cout << begin; counts++;
				if (counts % 10 == 0)
					cout << endl;
				else
					if(p!=N)
						cout << " ";
			}
		}
		begin++;
		if (p == N)
			break;
	}
	return 0;
}
1014 福尔摩斯的约会 (20分)

备注: 无

#include<bits/stdc++.h>
using namespace std;
int main() {
	string in1, in2, in3, in4;
	string day[] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
	cin >> in1 >> in2 >> in3 >> in4;
	int i = 0;
	for (; i < in1.length(); i++)
	{
		if ( isupper(in1[i])&&in1[i] == in2[i]) {
			int which = in1[i] - 'A';
			cout << day[which] << " ";
			break;
		}
	}
	for (i++; i < in1.length(); i++)
	{
		if (in1[i] == in2[i]) {
			if (isdigit(in1[i])) {
				cout << "0" << in1[i] << ":";
				break;
			}
			else if (in1[i] >= 'A'&&in1[i] <= 'N') {
				cout << 10 + (in1[i] - 'A') << ":";
				break;
			}
		}
	}
	for (int j = 0; j < in3.length(); j++)
	{
		if (((in3[j]>='a'&&in3[j]<='z')||(in3[j]>='A'&&in3[j]<='Z'))&& in3[j] == in4[j]) {
			printf("%02d", j); break;
		}
	}
}
1015 德才论 (25分)
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
class People {
public:
	int id;
	int defen;
	int caifen;
	int level;
	void  toString() {
		cout << id << " " << defen << " " << caifen << endl;
	}
	bool setLevel(int L, int H) {
		//cout << defen << "+" << caifen << endl;
		if (defen >= L && caifen >= L) {//被录取
		//录取等级
			if (defen >= H && caifen >= H) {
				this->level = 1;
			}
			else if (defen >= H && caifen < H) {
				this->level = 2;
			}
			else if (defen < H&&caifen < H&&defen >= caifen) {
				this->level = 3;
			}
			else {
				this->level = 4;
			}
			return true;
		}
		else {
			return false;
		}
	}
};
People p[100000];
bool cmp(People x, People o) {
	if (x.level != o.level) {
		return x.level < o.level;
	}
	if (x.caifen + x.defen != (o.caifen + o.defen)) {
		return x.caifen + x.defen > o.caifen + o.defen;
	}
	if (x.defen != o.defen) {
		return x.defen > o.defen;
	}
	if (x.id != o.id) {
		return x.id < o.id;
	}
	return true;
}

int main() {
	int N;int L;int H;
	int counts = 0;
	scanf("%d %d %d", &N, &L, &H);
	for (int i = 0; i < N; i++) {
		scanf("%d %d %d", &p[i].id, &p[i].defen, &p[i].caifen);
		bool flag = p[i].setLevel(L, H);
		if (flag) {
			counts++;
		}
		if (p[i].level == 0) {
			i--;
			N--;
		}
	}
	sort(p, p + counts, cmp);
	cout << counts<< endl;
	for (int i = 0; i < counts; i++) {
		p[i].toString();
	}
}

1016 部分A+B (15分)
#include<iostream>
using namespace std;
int main()
{
    long long A, B; int da, db;
    cin >> A >> da >> B >> db;
    int a = 0, b = 0;
    while(A!=0)
    {
        if(A%10 == da) a = a * 10 + da;
        A /= 10;
    }
    while(B!=0)
    {
        if(B%10 == db) b = b * 10 + db;
        B /= 10;
    }
    cout << a + b;
    return 0;
}
1017 A除以B (20分)
#include<iostream>
#include<string>
using namespace std;
int main() {
	string A; int B;
	int R;
	cin >> A >> B;
	if (A.size() == 1) {
		cout << (A[0] - '0') / B << " " << (A[0] - '0') % B << endl;
	}
	else {
		int temp = (A[0] - '0') * 10 + (A[1] - '0');
		for (int i = 0; i < A.size() - 1; i++) {
			int Q = temp / B;
			R = temp % B;
			temp = R * 10 + (A[i + 2] - '0'); //除法运算时,往后取一位,余数相应为乘以10
			cout << Q;
		}
		cout << " " << R;
	}
	return 0; 
}
1018 锤子剪刀布 (20分)

备注:写的好啰嗦,但是我懒的看

#include<iostream>
#include<string>
using namespace std;
int main() {
	int N;
	int jiaWin[3] = {0}, jiaLose=0;//B C J
	int yiWin[3] = {0}, yiLose=0;
	int ping=0;
	cin >> N;
	char jia, yi;
	for (int i = 0; i < N; i++)
	{
		cin >> jia >> yi;
		if (jia == 'J'&&yi == 'B') {
			jiaWin[0]++;
			yiLose++;
		}
		else if (jia=='C'&&yi=='J')
		{
			jiaWin[1]++;
			yiLose++;
		}
		else if (jia == 'B'&&yi == 'C') {
			jiaWin[2]++;
			yiLose++;
		}

		else if (yi == 'J'&&jia == 'B') {
			yiWin[0]++;
			jiaLose++;
		}
		else if (yi== 'C'&&jia == 'J')
		{
			yiWin[1]++;
			jiaLose++;
		}
		else if (yi == 'B'&&jia == 'C') {
			yiWin[2]++;
			jiaLose++;
		}
		else {
			ping++;
		}
	}
	cout << jiaWin[0] + jiaWin[1] + jiaWin[2] << " " << ping << " " << jiaLose << endl;
	cout << yiWin[0] + yiWin[1] + yiWin[2] << " " << ping << " " << yiLose << endl;
	int maxJia = jiaWin[0];
	int maxYi = yiWin[0];
	int index1 = 0,index2 = 0;
	for (int i = 1; i < 3; i++) {
		if (jiaWin[i] >= maxJia) {
			index1 = i;
		}
		if (yiWin[i] >= maxYi) {
			index2 = i;
		}
	}
	if (index1 == 0) {
		cout << "J" << " ";
	}
	else if (index1 == 1) {
		cout << "C" << " ";
	}
	else if (index1 == 2) {
		cout << "B" << " ";
	}
	if (index2 == 0) {
		cout << "J" ;
	}
	else if (index2 == 1) {
		cout << "C" ;
	}
	else if (index2 == 2) {
		cout << "B" ;
	}
	return 0;
}

1019 数字黑洞 (20分)

#include<bits/stdc++.h> 
using namespace std;
int main() {
	int num; cin >> num;
	do
	{
		string strNum = to_string(num);
		int arr[4] = { 0 };
		for (int i = 0; i < strNum.length(); i++)
			arr[i] = strNum[i]-'0';	
		sort(arr, arr + 4, greater<int>());
		int first = arr[0] * 1000 + arr[1] * 100 + arr[2] * 10 + arr[3];
		sort(arr, arr + 4, less<int>());
		int second = arr[0] * 1000 + arr[1] * 100 + arr[2] * 10 + arr[3];
		num = first - second;
		printf("%04d - %04d = %04d\n", first, second, num);
		if (num == 0) break;
	} while (num!=6174);	
}


1020 月饼 (25分)
#include<bits/stdc++.h> 
using namespace std;
class Moon {
public:
	double kuCun;
	double totalPrice;
	double price;
};
bool cmp(Moon x, Moon o) {
	return x.price > o.price;
}
int main() {
	int kind,maxNeed;
	double money=0;
	cin >> kind >> maxNeed;
	Moon m[1000];
	for (int i = 0; i < kind; i++)
	{
		cin >> m[i].kuCun;	
	}
	for (int i = 0; i < kind; i++)
	{
		cin >> m[i].totalPrice;
		m[i].price = m[i].totalPrice / m[i].kuCun;
	}
	sort(m, m + kind, cmp);
	for (int i = 0; i < kind; i++) {
		if (maxNeed < m[i].kuCun) {
			money = money + (maxNeed*m[i].price);
			break;
		}
		else {
			maxNeed = maxNeed - m[i].kuCun;
			money = money + m[i].totalPrice;
		}
	}
	printf("%.2f", money);	
}
1021 个位数统计 (15分)

备注:就拿个10位数组记录每个数字出现的次数

#include<bits/stdc++.h> 
using namespace std;
int main() {
	string input;cin >> input;
	int times[10] = {0};
	for (int i = 0; i < input.size(); i++)
	{
		int c = input[i]-48;
		times[c]++;
	}
	for (int i = 0; i < 10; i++)
	{
		if (times[i] == 0) continue;
		cout << i << ":" << times[i] << endl;
	}
}
1022 D进制的A+B (20分)

备注;栈。

#include<bits/stdc++.h> 
using namespace std;
int main() {
	int A, B, D;cin >> A >> B >> D;
	int result = A + B;
	stack<int>s;
	while (result != 0) {
		s.push(result % D);
		result = result / D;
	}
	if (s.empty()) {
		cout << 0;
	}
	while (!s.empty()) {
		cout << s.top();
		s.pop();
	}
	return 0;
}
1023 组个最小数 (20分)

备注:输入的十个数字代表每个相应数字出现的次数。

#include<bits/stdc++.h> 
using namespace std;
int main() {
	int arr[50]; int p = 0;
	for (int i = 0; i < 10; i++)
	{
		int temp; cin >> temp;
		for (int j = 0; j < temp; j++)
		{
			arr[p] = i; p++;
		}
	}
	sort(arr, arr + p, less<int>());
	int First, flag;
	for (int i = 0; i < p; i++)
	{
		if (arr[i] == 0) continue;
		flag = i;
		First = arr[i]; break;
	}
	cout << First;
	for (int i = 0; i < p; i++)
	{
		if (i == flag)continue;
		cout << arr[i];
	}
	return 0;
}
1024 科学计数法 (20分)

备注;无

#include<iostream>
#include<string>
using namespace std;
int main() {
	//+1.23400E-03
	string input; getline(cin , input);
	int indexE = input.find('E');
	string qianmian = input.substr(1, indexE-1);
	int indexP = qianmian.find('.');
	string temp = qianmian;
	qianmian.erase(indexP,1);//删了小数点
	int houmian=stoi(input.substr(indexE + 1, input.length() - indexE),0,10);
	if (input[0] == '-')
		cout << "-";
	if (houmian < 0) {
		cout << "0.";
		for (int i = 1; i <= abs(houmian)-1; i++)
			cout << "0";
		cout << qianmian;
	}
	else if (houmian == 0)
		cout << temp;
	else {
		if (qianmian.length() - 1 > houmian) {
			qianmian.insert(houmian + 1, ".");
			cout << qianmian;
		}
		else {
			cout << qianmian;
			for (int i = 1; i <= (houmian - (qianmian.length() - 1)); i++)
				cout << "0";
		}
	}
}
1025 反转链表 (25分)

备注:用个map储存记录下结点,然后根据地址按顺序放进vector,最后reverse(v.begin() + i, v.begin() + j);翻转。
打印是时的下一个结点地址灵活切换。

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
class Node {
public:
	int value,address,next;
};
int main() {
	int first, k, n;
	cin >> first >> n >> k;
	map<int, Node>m; vector<Node>v;
	for (int i = 0; i < n; i++)
	{
		int address,value,next; Node node;
		cin >> node.address >> node.value >> node.next;
		m[node.address]=node;
	}
	for (int i = 0; i < n; i++)
	{
		if (first == -1)
			break;
		if (m.count(first)) {
			v.push_back(m[first]);
			first = m[first].next;
		}
	}
	int i = 0; int j = i+k;
	while (j <= v.size())
	{
		reverse(v.begin() + i, v.begin() + j);
		i = j ;
		j= i + k ;
	}
	for (int i = 0; i < v.size(); i++)
	{
		printf("%05d %d ", v[i].address, v[i].value);
		if (i != v.size() - 1)
			printf("%05d\n", v[i + 1].address);
		else {
			cout << "-1" << endl;
		}
	}
}
1026 程序运行时间 (15分)

备注;栈。

#include<iostream>
using namespace std;
#define CLK_TCK 100
int main() {
	int c1, c2;cin >> c1 >> c2;
	float temp = (c2 - c1) / (CLK_TCK + 0.0);
	int allS = (c2 - c1) / CLK_TCK;
	if (allS + 0.5 <= temp) //四舍五入
		allS++;
	//1小时 60分 3600秒
	int hour = allS / 3600;
	allS -= hour * 3600;
	int min = allS / 60;
	allS -= min * 60;
    printf("%02d:%02d:%02d", hour, min, allS);
}
1027 打印沙漏 (20分)

备注;栈。

#include<bits/stdc++.h> 
using namespace std;
void printSpace(int num) {
	for (int i = 0; i < num; i++)
		cout << " ";
}
void printStar(int num,char c) {
	for (int i = 0; i < num; i++)
		cout << c;
	cout << endl;
}
int main() {
	int num;char c;
	cin >> num>>c;
	int maxOneSide = (num - 1) / 2;
	int t = 3,p=0;//p是一边有多少层
	int max = t; int shengyu;
	if (num < 7) {
		cout << c<< endl;
		cout << num - 1 << endl;
		return 0;
	}
	while (true) {
		if (t <= maxOneSide) {
			max += 2;
			p++; t += (max);
		}
		else {
			shengyu = num-(t - max)*2-1;
			break;
		}
	}
	max -= 2; int i = 0;
	for (; i <=p; i++)
	{
		printSpace(i);
		printStar(max,c);
		max -= 2;
	}
	i -= 2; max += 4;
	for (int j = 0; j < p; j++)
	{
		printSpace(i); i--;
		printStar(max, c);
		max += 2;
	}
	cout << shengyu;
}
1028 人口普查 (20分)

备注:这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过 200 岁的老人,
而今天是 2014 年 9 月 6 日,所以超过 200 岁的生日和未出生的生日都是不合理的,应该被过滤掉。
(string 类型可以直接比较大小,这里写蠢了。还自定义了方法比较,可恶)

#include<iostream>
#include<string>


using namespace std;
class Node {
public:
	string name;
	int year, month, day;
};
Node oldest, yougest;
bool bigerThan(Node node,Node t) {//node 比t大吗
	if (node.year != t.year)
		return node.year < t.year;
	if (node.month != t.month)
		return node.month < t.month;
	return node.day <= t.day;
}
int main() {
	int N; cin >> N; Node o, y; int cnt = 0;
	oldest.year = 1814; oldest.month=9; oldest.day = 6;
	yougest.year = 2014; yougest.month = 9; yougest.day = 6;
	for (int i = 0; i < N; i++)
	{
		Node temp; cin >> temp.name;
		scanf("%d/%d/%d", &temp.year, &temp.month, &temp.day);
		if (bigerThan(temp,yougest) && bigerThan(oldest,temp)) {
			if (cnt == 0) {
				o = temp; y = temp;
			}else {
				if (bigerThan(temp, o)) o = temp;
				if (bigerThan(y, temp)) y = temp;
			}
			cnt++;
		}
	}
	cout << cnt;
	if (cnt != 0) cout<<" "<< o.name << " " << y.name;
}
1029 旧键盘 (20分)
#include<iostream>
#include<string>
using namespace std;

int main() {
	string s1,s2,result="";
	cin >> s1>>s2;
	int i = 0; int j = 0;
	while (true)
	{	
		if (s2[s2.length()-1] == s1[i]&&j==s2.length()-1) {
			break;
		}
		if (s1[i] == s2[j]) {
			i++;
			j++;
		}
		else
		{
			char temp=s1[i];
			if (temp >= 'a'&&temp <= 'z' || (temp <= 'Z'&&temp >= 'A')) {
				if (temp >= 'a'&&temp <= 'z') {
					temp = temp - 32;
				}
			}
			if (result.find(temp) == result.npos) {//没找到
				result = result + temp;
			}			
			i++;
		}	
	}
	while (i < s1.length()-1) {//处理剩余部分
		i++;
		char temp = s1[i];
		if (temp >= 'a'&&temp <= 'z' || (temp <= 'Z'&&temp >= 'A')) {
			if (temp >= 'a'&&temp <= 'z') {
				temp = temp - 32;
			}
		}
		if (result.find(temp) == result.npos) {//没找到
			result = result + temp;
		}
	}
	cout << result;
	
}
1030 完美数列 (25分)
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int N, p;
	cin >> N >> p;
	long *a=new  long[N];
	for (int i = 0; i < N; i++)
		cin >> a[i];
	sort(a, a + N);
	int res = 0;//数列的最大长度
	for (int i = 0; i < N; i++) {//找以各个元素为最小值的,完美数列的最大长度
		for (int j = i + res; j < N; j++) {//直接从i+res的索引开始,因为前面的没必要比了。妙不可言
			if (a[j] <= a[i] * p) res++;
			else break;
		}
	}
	cout << res;

}
1031 查验身份证 (15分)
#include <iostream>
#include<string>
using namespace std;
char whichM[] = { '1', '0', 'X' ,'9','8', '7', '6' ,'5' ,'4', '3', '2' };
int weight[] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
int main() {
	int n; bool flag = true;
	cin >> n;
	string *arr = new string[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
		string c = arr[i];
		for (int j = 0; j < arr[i].length() - 1; j++)
			sum = sum + (c[j] - '0')*weight[j];
		int Z = sum % 11; sum = 0;
		if (whichM[Z] != c[c.length() - 1]) {
			cout << c << endl;
			flag = false;
		}
	}
	if (flag) cout << "All passed";
}
1032 挖掘机技术哪家强 (20分)
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	double infor[100000] = {0};
	cin >> N;
	int id = 0;double score;
	double maxScore = -1;int maxIndex = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> id >> score;
		infor[id] += score;
		if (infor[id] > maxScore) {
			maxScore = infor[id];
			maxIndex = id;
		}
	}
	sort(infor, infor + 100000, greater<double>());
	cout <<maxIndex<<" "<< infor[0];
}
1033 旧键盘打字 (20分)
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s1, s2; getline(cin, s1); getline(cin, s2);
	bool have=true ;//有没有上档键
	if (s1.find('+') == string::npos)
		have = false;
	for (int i = 0; i < s2.length(); i++)
	{
		char t = s2[i]; 
		char t2 = t;//记录t的大写形式
		if (t >= 'a'&&t <= 'z')
			t2 = t - 32;
		if (have && (t >= 'A'&&t <= 'Z'))//上档键坏了,所有的大写字母都直接过
			continue;
		if (have&&s1.find(t2) != string::npos)//上档键坏了,查一下这个字符有没有坏,要用大写查
			continue;
		if (s1.find(t2) == string::npos)
			cout << t;
	}
}
1034 有理数四则运算 (20分)
#include <iostream>
#include <cmath>
using namespace std;
long long a, b, c, d;
long long gcd(long long t1, long long t2) {
    return t2 == 0 ? t1 : gcd(t2, t1 % t2);
}
void func(long long m, long long n) {
    if (m * n == 0) {
        printf("%s", n == 0 ? "Inf" : "0");
        return ;
    }
    bool flag = ((m < 0 && n > 0) || (m > 0 && n < 0));
    m = abs(m); n = abs(n);
    long long x = m / n;
    printf("%s", flag ? "(-" : "");
    if (x != 0) printf("%lld", x);
    if (m % n == 0) {
        if(flag) printf(")");
        return ;
    }
    if (x != 0) printf(" ");
    m = m - x * n;
    long long t = gcd(m, n);
    m = m / t; n = n / t;
    printf("%lld/%lld%s", m, n, flag ? ")" : "");
}
int main() {
    scanf("%lld/%lld %lld/%lld", &a, &b, &c, &d);
    func(a, b); printf(" + "); func(c, d); printf(" = "); func(a * d + b * c, b * d); printf("\n");
    func(a, b); printf(" - "); func(c, d); printf(" = "); func(a * d - b * c, b * d); printf("\n");
    func(a, b); printf(" * "); func(c, d); printf(" = "); func(a * c, b * d); printf("\n");
    func(a, b); printf(" / "); func(c, d); printf(" = "); func(a * d, b * c);
    return 0;
}
**1035 插入与归并 (25分)
1036 跟奥巴马一起编程 (15分)
#include<iostream>
using namespace std;
int main() {
	int num; char C;
	cin >> num >> C;
	int row = num; int col = 0;
	float temp = num / 2.0;
	num /= 2;
	if ( temp-num>=0.5) 
		num++;
	col = num;
	for (int i = 1; i <= col; i++)
	{
		for (int j = 1; j <= row; j++) {
			if (i == 1 || j == 1 || i == col || j == row) cout << C;
			else cout << " ";
		}
		cout << endl;
	}
}
1037 在霍格沃茨找零钱 (20分)
#include<iostream>
#include<string>
using namespace std;
//1G=17S=17*29K;
int main() {
	string c="";
	//10.16.27 14.1.28
	int RG, RS, RK; int AG, AS, AK;
	scanf("%d.%d.%d",&RG,&RS,&RK);
	int PALL = RG * 493 + RS * 29 + RK;
	scanf("%d.%d.%d", &AG, &AS, &AK);
	int AALL= AG * 493 + AS * 29 + AK;
	int chaK=AALL-PALL;
	if (chaK < 0) {
		c = "-";
		chaK = abs(chaK);
	}
	RG = chaK / 493;
	RS = (chaK - (RG * 493)) / 29;
	RK = chaK-(RG*493)-(RS * 29);
	cout << c << RG << "." << RS << "." << RK;
	return 0;
}
1038 统计同成绩学生 (20分)
#include<bits/stdc++.h>
using namespace std;
int main() {
	int counts[101] = {0};
	int n,m; int temp;
	cin >> n; 
	for (int i = 0; i < n; i++)
	{	
		cin >> temp;
		counts[temp]++;
	}
	cin >> m;
	int *seach = new int[m];
	for (int i = 0; i < m; i++)
		cin>>seach[i];
	for (int i = 0; i < m; i++)
	{	
		if (i==0) cout << counts[seach[i]];
		else  cout <<" "<<counts[seach[i]];
	}
}
1039 到底买不买 (20分)

备注:
在这里插入图片描述

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

int main() {
	string s1, s2; bool isYes = true;
	cin >> s1 >> s2;
	int noCount = 0; int yesCount = s1.length() - s2.length();
	for (int i = 0; i < s2.length(); i++)
	{
		int F = s1.find(s2[i]);
		if (F == -1) {
			isYes = false;
			noCount++;
		}
		else {
			s1.erase(F, 1);
		}
	}
	if (isYes)
	{
		cout << "Yes" <<" "<< yesCount;
	}
	else {
		cout << "No" << " " << noCount;
	}
}
1040 有几个PAT (25分)

备注:以某个A为基准点,由这个A构成的PAT字符串有多少个?
countp * countt;//p和t的组合


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s; cin >> s;
	long count = 0, countt = 0, countp = 0;
	for (int i = 0; i <s.length(); i++) {
		if (s[i] == 'T')
			countt++;
	}
	for (int i = 0; i <s.length(); i++) {
		if (s[i] == 'P')
			countp++;
		if (s[i] == 'T')
			countt--;
        //上述两行后,p和t各有几个呢?
		if (s[i] == 'A')
			count += countp * countt;//p和t的组合
	}
	printf("%d", count % 1000000007);
	return 0;
}


1041 考试座位号 (15分)
#include <iostream>
using namespace std;
class stu{
public:
    string stuNum;
    int num;
    void toString(){
        cout<<stuNum<<" "<<num<<endl;
    }
};
stu stus[1001];
int main(){
    int T,M,m;cin>>T;
    for(int i=0;i<T;i++){
        int index;stu s;
        cin>>s.stuNum>>index>>s.num;
        stus[index]=s;
    }
    cin>>M;
    while(M--){
        cin>>m;
        stus[m].toString();
    }
}

1042 字符统计 (20分)
#include<bits/stdc++.h>
using namespace std;
int main() {
	vector<char> v;int arr[26] = { 0 };
	string in; getline(cin, in);
	int max = -1;
	for (int i = 0; i < in.length(); i++)
	{
		char temp = in[i];
		if (!isalpha(temp)) continue;
		if (temp >= 'A'&&temp <= 'Z') temp += 32;
		int index = temp - 'a'; arr[index]++;
		if (arr[index] > max) {
			v.clear();
			v.push_back(temp);
			max = arr[index];
		}
		else if (arr[index] == max) 
			v.push_back(temp);
	}
	sort(v.begin(), v.end());
	cout << v[0] << " " << arr[v[0] - 'a'];
}
1043 输出PATest (20分)
#include<bits/stdc++.h>
using namespace std;
int main() {
	string input; cin >> input;
	int P = 0,A=0,T=0,e=0,s=0,t=0;
	for (int i = 0; i < input.length(); i++)
	{
		switch (input[i]) {
		case 'P':P++; break;
		case 'A':A++; break;
		case 'T':T++; break;
		case 'e':e++; break;
		case 's':s++; break;
		case 't':t++; break;
		}
	}
	int maxSize=max(max(max(max(max(P, A), T), e), s), t);
	for (int i = 1; i <= maxSize; i++)
	{
		if (i <= P) cout << 'P';
		if (i <= A) cout << 'A';
		if (i <= T) cout << 'T';
		if (i <= e) cout << 'e';
		if (i <= s) cout << 's';
		if (i <= t) cout << 't';
	}
}
**1044 火星数字 (20分)

备注:copy
分析:因为给出的可能是数字(地球文)也有可能是字母(火星文),所以用字符串s保存每一次的输入,因为如果是火星文则会出现空格,所以用getline接收一行的输入~计算string s的长度len,判断s[0]是否是数字,如果是数字,表示是地球文,则需要转为火星文,执行func1();如果不是数字,则说明是火星文,需要转为地球文,执行func2();

func1(int t)中,传入的值是string转int后的结果stoi(s),因为数字最大不超过168,所以最多只会输出两位火星文,如果t / 13不等于0,说明有高位,所以输出b[t/13];如果输出了高位(t/13不等于0)并且t % 13不等于0,说明有高位且有低位,所以此时输出空格;如果t % 13不等于0,说明有低位,此时输出a[t % 13];注意,还有个数字0没有考虑,因为数字0取余13等于0,但是要特别输出tret,所以在func1的最后一句判断中加一句t == 0,并将a[0]位赋值成tret即可解决0的问题~

func2()中,t1和t2一开始都赋值0,s1和s2用来分离火星文单词,因为火星文字符串只可能一个单词或者两个单词,而且一个单词不会超过4,所以先将一个单词的赋值给s1,即s1 = s.substr(0, 3);如果len > 4,就将剩下的一个单词赋值给s2,即s2 = s.substr(4, 3);然后下标j从1到12遍历a和b两个数组,如果a数组中有和s1或者s2相等的,说明低位等于j,则将j赋值给t2;如果b数组中有和s1相等的(b数组不会和s2相等,因为如果有两个单词,s2只可能是低位),说明高位有值,将j赋值给t1,最后输出t1 * 13 + t2即可~
https://blog.csdn.net/liuchuo/article/details/51994339

#include <iostream>
#include <string>
using namespace std;
string a[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string b[13] = {"####", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
string s;
int len;
void func1(int t) {
    if (t / 13) cout << b[t / 13];
    if ((t / 13) && (t % 13)) cout << " ";
    if (t % 13 || t == 0) cout << a[t % 13];
}
void func2() {
    int t1 = 0, t2 = 0;
    string s1 = s.substr(0, 3), s2;
    if (len > 4) s2 = s.substr(4, 3);
    for (int j = 1; j <= 12; j++) {
        if (s1 == a[j] || s2 == a[j]) t2 = j;
        if (s1 == b[j]) t1 = j;
    }
    cout << t1 * 13 + t2;
}
int main() {
    int n;
    cin >> n;
    getchar();
    for (int i = 0; i < n; i++) {
        getline(cin, s);
        len = s.length();
        if (s[0] >= '0' && s[0] <= '9')
            func1(stoi(s));
        else
            func2();
        cout << endl;
    }
    return 0;
}
**1045 快速排序 (25分)

在这里插入图片描述

#include <iostream>
#include <algorithm>
#include <vector>
//大神代码
int a[100000], b[100000], v[100000];
using namespace std;
int main() {
	int n, max = 0, cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
	}
	sort(a, a + n);//排序
	for (int i = 0; i < n; i++) {//     a[i] 1 2 3 4 5
		if (a[i] == b[i] && b[i] > max)//b[i] 1 3 2 4 5 原序列
			v[cnt++] = b[i];
		else if (b[i] > max)
			max = b[i];
	}
	printf("%d\n", cnt);
	for (int i = 0; i < cnt; i++) {
		if (i != 0) printf(" ");
		printf("%d", v[i]);
	}
	printf("\n");//不加这句会有一个测试点没法通过。.
	return 0;
}
1046 划拳 (15分)
#include<bits/stdc++.h>
using namespace std;
class huige {
public:
	int jhan, jhua;
	int yhan, yhua;
	string whoWin() {
		if (jhua==yhua)
			return "NOBODY";
		if (jhua == jhan + yhan) 
			return "jia";
		if (yhua==jhan+yhan)
			return "yi";
		return "NOBODY";
	}
};
int main() {
	int N; cin >> N;
	int jhe = 0, yhe = 0;
	for (int i = 0; i < N; i++)
	{	
		huige h;
		cin >> h.jhan >> h.jhua >> h.yhan >> h.yhua;
		if (h.whoWin() == "jia")
			yhe++;
		else if (h.whoWin() == "yi")
			jhe++;
	}
	cout << jhe << " " << yhe << endl;
}
1047 编程团体赛 (20分)
#include <iostream>
using namespace std;
int main() {
	int teamNum[1001] = { 0 }, team, max, score, T;
	cin >> T;
	while (T--) {
		scanf("%d-%d %d", &team, &max, &score);
		teamNum[team] += score;
	}
	max = 0;
	for (int i = 0; i < 1001; i++) {
		if (teamNum[i] > teamNum[max]) max = i;
	}
	cout << max << " " << teamNum[max];
	return 0;
}
1048 数字加密 (20分)
#include<iostream>
#include<stack>
using namespace std;
int main() {
    string s,s2;
    cin>>s>>s2;
    stack<int> sta1,sta2;
    stack<char> res;
    int tmp1,tmp2,tmpRes;
    for(int i=0;i<s.length();i++){
        sta1.push(s[i]-'0');
    }
    for(int i=0;i<s2.length();i++){
        sta2.push(s2[i]-'0');
    }
    bool isOdd=true;
    while(!sta1.empty()||!sta2.empty()){
        //取数值
        if(!sta1.empty()) {
            tmp1=sta1.top();
            sta1.pop();
        }else{
            tmp1=0;
        }
        if(!sta2.empty()) {
            tmp2=sta2.top();
            sta2.pop();
        }else{
            tmp2=0;
        }
        //奇偶处理数据
        if(isOdd){
            tmpRes=(tmp1+tmp2)%13;
            switch(tmpRes){
                case 10:res.push('J');break;
                case 11:res.push('Q');break;
                case 12:res.push('K');break;
                default:res.push(tmpRes+'0');break;
            }
        }else{
            tmpRes=tmp2-tmp1;
            if(tmpRes<0)tmpRes+=10;
            res.push(tmpRes+'0');
        }
        isOdd=!isOdd;
    }
    //output
    while(!res.empty()){
        cout<<res.top();
        res.pop();
    }
    system("pause");
    return 0;
}

1049 数列的片段和 (20分)
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N; double sum = 0;
	double *num = new double[N];
	for (int  i = 0; i < N; i++)
		cin >> num[i];
	for (int i = 0; i < N; i++)
		sum += num[i] * (N - i)*(i+1);
	printf("%.2f", sum);
}
1050 螺旋矩阵 (25分)
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;int *num = new int[N];
	for (int i = 0; i < N; i++)
		scanf("%d", &num[i]);
	sort(num, num + N, greater<int>());
	int hang, lie;//作为遍历num[]的索引
	for (int i = 1; i <= sqrt(N); i++) 
		if (N%i == 0) lie = i;
	hang = N / lie;
	if (lie > hang) swap(lie, hang);
	int **arr = new int*[hang];//m行n列型
	int p = 0;//索引
	for (int i = 0; i < hang; ++i) 
		arr[i] = new int[lie];
	int i = 0, j = 0;
	int rightF = lie-1,leftF=0,upF=0,downF=hang-1;
	while (true)
	{
		while (j <= rightF) 
			arr[i][j++] = num[p++];
		i++; j--; upF++;
		if (p >= N) break;
		while (i<=downF)
			arr[i++][j] = num[p++];
		i--; j--; rightF--;
		if (p >= N) break;
		while (j>=leftF)
			arr[i][j--] = num[p++];
		i--; j++; downF--;
		if (p >= N) break;
		while (i>=upF)
			arr[i--][j] = num[p++];	
		i++; j++; leftF++;
		if (p >= N) break;
	}
	for (int i = 0; i < hang; i++)
	{
		for (int j = 0; j < lie; j++) {
			printf("%d", arr[i][j]);
			if (j != lie - 1)printf(" ");
		}
		cout << endl;
	}
}
1051 复数乘法 (15分)
#include<bits/stdc++.h>
using namespace std;

int main() {
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	double real1 = a * cos(b);
	double imag1 = a * sin(b);

	double real2= c * cos(d);
	double imag2 = c * sin(d);

	double real3 = (real1*real2)-(imag1 *imag2);
	double imag3 = real1 * imag2 + real2 * imag1;
	
	if (fabs(real3)<0.01)
		real3 = 0;
	if (fabs(imag3)<0.01)
	{
		imag3 = 0;
	}
	printf("%.2f", real3);
	if (imag3>=0)
		cout<<"+";
	printf("%.2fi", imag3);

}
1052 卖个萌 (20分)
1053 住房空置率 (20分)
#include<bits/stdc++.h>
using namespace std;

int main() {
	int N, D; double e;
	int n1=0, n2=0;
	cin >> N >> e >> D;
	for (int i = 0; i < N; i++)
	{
		int counts = 0;
		int K; cin >> K;
		for (int j = 0; j <K; j++)
		{
			double temp; cin >> temp;
			if (temp < e) counts++;
		}
		if (counts > (K / 2) && K > D) n2++;
		if (counts>(K/2)&& K <= D) n1++;
	}
	printf("%.1f", n1 / (N + 0.0) * 100);printf("%% ");
	printf("%.1f", n2 / (N + 0.0) * 100);printf("%%");
}
1054 求平均值 (20分)
#include<iostream>	
#include<string>

using namespace std;
bool isRight(string temp) {
	if (temp.find('.')==0||temp.find_first_of('.')!=temp.find_last_of('.'))//首个是点,或者多个点
		return false;
	for (int i = 0; i < temp.length(); i++)//不是数字,或也不是首位是-,或者也不是.
	{
		char c = temp[i];
		if (!isdigit(c)&&!(i == 0 && temp[i] == '-')&&temp[i]!='.') return false;    
	}
	double t= stod(temp, 0);//上述做完,这个字符串一定是数字类型的了
	if (t>1000||t<-1000) return false;//超范围
	if (temp.find('.')==-1)return true;//范围内整数
	if (temp.length()- temp.find('.')<=3)return true;//范围内两位小数
	return false;
}
int main() {
	int N; cin >> N; double sum = 0;
	bool t = false; int n = 0;
	for (int i = 0; i < N; i++)
	{
		string temp; cin >> temp;
		if (isRight(temp))
		{
			sum += stod(temp, 0); n++;
			t = true;
		}
		else
			cout << "ERROR: " << temp << " is not a legal number" << endl;		
	}
	if (t)
	{
        if (n==1 )cout << "The average of "<<n <<" number is ";
        else  cout << "The average of "<<n <<" numbers is ";
		printf("%.2f", sum / n);
	}
	else 
		cout << "The average of 0 numbers is Undefined" << endl;
}
1055 集体照 (25分)
#include<iostream>	
#include<string>
#include<algorithm>
using namespace std;
class stu {
public:
	string name;
	int height;
};
bool cmp(stu s1, stu s2) {
	if (s1.height!=s2.height)
		return s1.height> s2.height;
	return s1.name < s2.name;	
}
int main() {
	int N, K; cin >> N >> K;
	stu *s = new stu[N];
	int duoyuderen = N % K;
	int num = N / K;
	for (int i = 0; i < N; i++)
		cin >> s[i].name >> s[i].height;
	sort(s, s + N, cmp);//排序
	int p = 0;
	for (int i = 0; i < K; i++)
	{
		int n = num;//n是当前排 的人数
		if (i == 0)//第一次要加上多于的人,放在最后一排
			n+=duoyuderen;
		stu *temp = new stu[n];
		int middle = n / 2 ; int left = middle-1, right = middle+1;
		temp[middle] = s[p]; p++;
		while (left>=0||right<=n-1)//交叉着当进去
		{
			if (left >= 0) {
				temp[left] = s[p]; left--; p++;
			}
			if (right<=n-1)
			{
				temp[right] = s[p]; right++; p++;
            }
		}
		for (int l = 0; l <n; l++)
		{
			if (l != 0)
				cout << " ";
			cout << temp[l].name;
		}
		cout << endl;
	}
}
1057 数零壹 (20分)
#include<bits/stdc++.h>
using namespace std;
//PAT (Basic)

int main() {
	string input; getline(cin, input); int sum = 0,count1=0,count2=0;
	for (int i = 0; i < input.length(); i++)
	{	
		char temp = input[i];
		if (isalpha(temp)) {
			if (islower(temp)) 
				temp -= 32;//小写变大写
		}
		else continue;	//不是字母直接跳过
		int t = temp - 64; 
		sum += t;
	}
	while (sum > 0)
	{
		if (sum % 2 == 0)
			count1++;
		else count2++;
		sum = (sum - sum % 2) / 2;
	}
	cout << count1<<" "<<count2<<endl;
}
1059 C语言竞赛 (20分)

//备注,

#include<bits/stdc++.h>
using namespace std;
class Que {//每一个题目   
public:
	int id;
	int maxScore;//满分分值
	int chooseNum;//本题几个选项
	int rightNum;//几个正确选项
	char *rightAnswer;//正确答案
	int errorTimes = 0;
	void init(int id) {
		this->id = id;
		cin >> maxScore >> chooseNum >> rightNum;
		rightAnswer = new char[rightNum];
		for (int i = 0; i < rightNum; i++)
			cin >> rightAnswer[i];
	}
};
class Stu {
public:
	int defen = 0;
	Que *stiku;
	void init(int M, string temp) {
		stiku = new Que[M];
		int p = 0, i = 0;
		for (int j = 0; j < temp.length(); j++) {
			if (temp[j] == ')')//一道题输入完成了	
				i++; p = 0;
			if (temp[j] <= '5'&&temp[j] >= '0')
			{
				stiku[i].rightNum = temp[j] - 48;
				stiku[i].rightAnswer = new char[stiku[i].rightNum];
			}if (isalpha(temp[j]))
			{
				stiku[i].rightAnswer[p] = temp[j];
				p++;
			}

		}
	}
};
bool gaifen(char* rightAnswer, char* sAnswer, int n) {
	for (int i = 0; i < n; i++)
		if (rightAnswer[i] != sAnswer[i])
			return false;
	return true;
}
bool cmp(Que a, Que b) {
	if (a.errorTimes != b.errorTimes)
		return a.errorTimes > b.errorTimes;
	return a.id < b.id;
}
int main() {
	int N, M; cin >> N >> M;
	Que *tiku = new Que[M];
	Stu *s = new Stu[N];//所有学生
	for (int i = 0; i < M; i++)
		tiku[i].init(i + 1);
	getchar();
	for (int i = 0; i < N; i++)//每个学生需要做M个题目
	{
		string temp; getline(cin, temp);
		s[i].init(M, temp);
	}
	//下面开始改题目
	for (int i = 0; i < N; i++)//xuesheng
	{
		for (int j = 0; j < M; j++) {//tihao
			if (s[i].stiku[j].rightNum != tiku[j].rightNum)//选的个数都不对了
			{
				tiku[j].errorTimes++;
				continue;//改这个同学的下一题
			}
			else {
				if (gaifen(tiku[j].rightAnswer, s[i].stiku[j].rightAnswer, tiku[j].rightNum))
					s[i].defen += tiku[j].maxScore;
				else
					tiku[j].errorTimes++;
			}
		}
		cout << s[i].defen << endl;
	}
	sort(tiku, tiku + M, cmp);
	if (tiku[0].errorTimes == 0)
		cout << "Too simple";
	else {
		cout << tiku[0].errorTimes << " ";
		for (int j = 0; j < M; j++) {//tihao
			if (tiku[j].errorTimes == tiku[0].errorTimes)
			{
				if (j != 0)
					cout << " ";
				cout << tiku[j].id;
			}

		}
	}


}
1047 编程团体赛 (20分)
#include <stdio.h>

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

int main()
{
	int award[10000] = { 0 }, N, K, ID;

	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &ID);
		if (i == 0)              award[ID] = 1;
		else if (isPrime(i + 1)) award[ID] = 2;
		else                    award[ID] = 3;
	}
	scanf("%d", &K);
	for (int i = 0; i < K; i++)
	{
		scanf("%d", &ID);
		switch (award[ID])
		{
		case 0: printf("%04d: Are you kidding?\n", ID);               break;
		case 1: printf("%04d: Mystery Award\n", ID);  award[ID] = 4;  break;
		case 2: printf("%04d: Minion\n", ID);         award[ID] = 4;  break;
		case 3: printf("%04d: Chocolate\n", ID);      award[ID] = 4;  break;
		case 4: printf("%04d: Checked\n", ID);                        break;
		}
	}

	return 0;
} 
1061 判断题 (15分)
#include<bits/stdc++.h>
using namespace std;

int main() {
	int N, M; cin >> N >> M;
	int **arr=new int*[2];//两行M列
	for (int i = 0; i < 2; i++)
		arr[i] = new int[M];
	for (int i = 0; i < M; i++)
		cin >> arr[0][i];
	for (int i = 0; i < M; i++)
		cin >> arr[1][i];
	for (int i = 0; i < N; i++)
	{	
		int sum = 0;
		for (int j = 0; j < M; j++) {
			int temp; cin >> temp;
			if (temp==arr[1][j])
				sum += arr[0][j];
		}
		cout << sum << endl;
	}

}
1047 编程团体赛 (20分)
#include<iostream>
using namespace std;
bool zuijian(int a, int b) {
	for (int i = 2; i <=a; i++)
	{
		if (a%i == 0 && b%i == 0)
			return false;
	}
	return true;
}
int main() {
	double a, b, a1, b1,K;
	scanf("%lf/%lf %lf/%lf %lf", &a, &b, &a1, &b1, &K);
	double d = a / b; double d1 = a1 / b1;
	if (d > d1)
		swap(d, d1);
	int t1 = d * K; t1++;
	bool f = false;
	for (int i = t1; i/K <d1; i++)
	{
		if (zuijian(i, K)) {
			if (f)
				cout <<" ";
			cout << i << "/" << K;
			f = true;
		}
	}

}
1047 编程团体赛 (20分)
#include<bits/stdc++.h>
using namespace std;

int main() {
	int N,max=0; cin >> N;
	for (int i = 0; i < N; i++)
	{
		int n,m; cin >> n >> m;
		if (n*n+m*m>max)
			max = n * n + m * m;
	}
	printf("%.2f", sqrt(max));

}
1047 编程团体赛 (20分)
#include<bits/stdc++.h>
using namespace std;

int main() {
	int N; cin >> N; bool F = true;
	set<int>s;
	for (int i = 0; i < N; i++)
	{
		string temp; cin >> temp;
		int sum = 0; int len = temp.length();
		for (int i = 0; i < len; i++)
			sum += temp[i] - '0';	
		s.insert(sum);
	} 
	set<int>::iterator it;
	cout << s.size() << endl;
	for (it = s.begin(); it != s.end(); it++)
	{
		if (it != s.begin())
			cout << " ";
		printf("%d", *it);
	}

}
1047 编程团体赛 (20分)
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	map<int, int>m;
	int N; cin >> N;
	for (int i = 0; i < N; i++)
	{
		int t1, t2; cin >> t1 >> t2;
		m[t1] = t2;
		m[t2] = t1;
	}
	int M; cin >> M;
	vector<int> v; int a[100000] = { 0 };
	for (int i = 0; i < M; i++)
	{
		int temp; cin >> temp;
		a[temp] = 1;
		v.push_back(temp);
	}

	for (int i = 0; i < v.size(); i++)
	{
		//vector<int>::iterator it
		map<int, int>::iterator iter;
		iter = m.find(v[i]);

		if (iter == m.end()) {
			//根本没有对象
			continue;
		}
		//找到了,他是有对象的人
		if (a[m[v[i]]] == 1)//对象来了吗
            
		{//对象来了,把它从单身狗中删除
			v.erase(v.begin()+i);
			i--;
		}
	}
	sort(v.begin(), v.end());
	cout <<v.size()<<endl;
	for (int i = 0; i < v.size(); i++)
	{
		if (i != 0)
			cout << " ";
		printf("%05d",v[i]);
	}
}
1047 编程团体赛 (20分)
#include<bits/stdc++.h>
using namespace std;
int main() {
	int M, N, A, B, Temp;
	cin >> M >> N >> A >> B >> Temp;
	for (int i = 0; i < M; i++)
	{
		for (int j = 0; j < N; j++) {
			int t; scanf("%d",&t);
			if (j!=0)
				cout << " ";
			if (t<=B&&t>=A)
				printf("%03d", Temp);
			else 
				printf("%03d", t);
		}
		printf("\n");
	}
}
1047 编程团体赛 (20分)
#include<iostream>
#include<string>
using namespace std;
int main() {
	string rightpw; int times; cin >> rightpw >> times;
	int errorTimes = 0; getchar();
	while (true)
	{
		string temp; getline(cin, temp);
		if (temp=="#")			break;
		
		if (temp==rightpw)
		{
			cout << "Welcome in";
			return 0;
		}
		else {
			cout << "Wrong password: "<<temp<<endl;
			errorTimes++;
		}
		if (errorTimes==times)
		{
			cout << "Account locked" << endl;
			break;
		}
	}
}
1047 编程团体赛 (20分)
1047 编程团体赛 (20分)
#include<iostream>
#include<string>
using namespace std;
bool findWin(string *wein, string temp, int p) {
	for (int i = 0; i < p; i++)
	{
		if (wein[i] == temp)
			return true;
	}
	return false;
}
int main() {
	int M, N, S; cin >> M >> N >> S;
	string *winName = new string[1000]; int p = 0;
	int counts = 1;
	for (int i= 1; i <= M; i++)
	{
		string temp; cin >> temp;
		if ((counts - S) % N == 0&& counts - S>=0) {
			if (!findWin(winName,temp,p))//没兑过奖
			{
				cout << temp << endl; 
				winName[p] = temp; p++;
				counts++;
			}	
		}
		else {
			counts++;
		}
	}
	if (p == 0) {
		cout << "Keep going..."<<endl;
	}
}
1047 编程团体赛 (20分)
#include <iostream>
#include<algorithm>
using namespace std;
int main() {
	int N; cin >> N;
	int *arr = new int[N];
	for (int i = 0; i < N; i++)
		cin >> arr[i];
	sort(arr, arr + N);//升序排序
	int result = arr[0];
	for (int i = 1; i < N; i++)
		result = (result + arr[i]) / 2;
	printf("%d", result);
}
1071 小赌怡情 (15分)
#include<iostream>
using namespace std;
int main() {
	int T, K; cin >> T >> K;
	for (int i = 0; i < K; i++)
	{
		int n1, b, t, n2; cin >> n1 >> b >> t >> n2;
		if (t > T) {
			cout << "Not enough tokens.  Total = "<<T<<"."<<endl;
			continue;
		}
		if ((n1 < n2&&b == 1) || (n1 > n2) && b == 0) {
			T += t;
			cout << "Win "<<t<<"!  Total = "<<T<<"." << endl;
		}
		else {
			T -= t;
			cout << "Lose "<<t<<".  Total = "<<T<<"." << endl;
		}
		if (T == 0) {
			cout << "Game Over." << endl;
			return 0;
		}
	}

}
1047 编程团体赛 (20分)
#include<iostream>
#include<string>
using namespace std;

int main() {
	int N, M; cin >> N >> M;
	int stu = 0,illegal=0;
	int arr[10000] = { 0 };
	for (int i = 0; i < M; i++)
	{
		int temp; cin >> temp;
		arr[temp] = 1;
	}
	for (int i = 0; i < N; i++)
	{
		string name; int t; cin >> name>>t;
		bool f = false;
		for (int j = 0; j < t; j++)
		{

			int Temp; cin >> Temp;
			if (arr[Temp]!=0)
			{
				if (!f) {
					cout << name<<":"; f = true;
					stu++;
				}
				printf(" %04d", Temp);
				illegal++;
			}
		}
		if (f)
		{
			printf("\n");
		}
	}
	cout << stu << " " << illegal << endl;
}
1047 编程团体赛 (20分)
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
class timu {
public:
	int no; double maximum; int num,rightnum;
	map<char, bool>answer;//本题的正确答案
	map<char, int>m;//本题每个选项错误的次数
	//初始错误的选项,错误次数是0,学生每选错一次,次数就加1;
	//初始正确的选项,错误次数是学生数量,对一次,就减一
	void init(int n,int no) {
		this->no = no;
		cin >> maximum >> num >> rightnum;
		answer['a'] = false; answer['b'] = false; answer['c'] = false;
		answer['d'] = false; answer['e'] = false;
		m['a'] = 0; m['b'] = 0; m['c'] = 0; m['d'] = 0; m['e'] = 0;
		for (int i = 0; i < rightnum; i++)
		{
			char temp; cin >> temp;
			answer[temp] = true;
			m[temp] = n;
		}
	}
};

int main() {
	int N, M; cin >> N >> M;
	timu *tk = new timu[M];
	for (int i = 0; i < M; i++)
		tk[i].init(N,i+1);	
	for (int i = 0; i < N; i++)//学生
	{
		double sum = 0;//这位同学的最终得分
		for (int j = 0; j < M; j++)//题目
		{
			getchar();
			int a; bool isFalse = true;
			scanf("(%d", &a);
			for (int k = 0; k < a; k++)//读入某个同学某个题目的各个选项
			{
				char temp; scanf(" %c", &temp);
				if (tk[j].answer[temp]==false)
				{
					tk[j].m[temp]++;//错误选项加一
					isFalse = false;
				}
				else {
					tk[j].m[temp]--;//正确选项的错误次数减一
				}
			}
			char wuyong; scanf("%c", &wuyong);
			//开始判分
			if (isFalse&&a == tk[j].rightnum) {//全对
				sum += tk[j].maximum;
			}
			if(isFalse&&a != tk[j].rightnum)//对了部分
				sum+= tk[j].maximum/2;
		}
		printf("%.1f\n", sum);
	}
	int max=0;
	for (int i = 0; i < M; i++)
	{
		if (tk[i].m['a'] > max)
			max = tk[i].m['a'];
		if (tk[i].m['b'] > max)
			max = tk[i].m['b'];
		if (tk[i].m['c'] > max)
			max = tk[i].m['c'];
		if (tk[i].m['d'] > max)
			max = tk[i].m['d'];
		if (tk[i].m['e'] > max)
			max = tk[i].m['e'];
	}
	if (max == 0) {
		cout << "Too simple" << endl; return 0;
	}
	for (int i = 0; i < M; i++)
	{//2 3-b
		if (tk[i].m['a'] == max)
			cout << max << " " << i + 1 << "-" << "a" << endl;
		if (tk[i].m['b'] == max)
			cout << max << " " << i + 1 << "-" << "b" << endl;
		if (tk[i].m['c'] == max)
			cout << max << " " << i + 1 << "-" << "c" << endl;
		if (tk[i].m['d'] == max)
			cout << max << " " << i + 1 << "-" << "d" << endl;
		if (tk[i].m['e'] == max)
			cout << max << " " << i + 1 << "-" << "e" << endl;
	}
}
1074 宇宙无敌加法器 (20分)

//备注小细节很多

#include<iostream>
#include<math.h>
#include<string>
#include<stack>
using namespace std;
int main() {
	string a, b, c; stack<int>s1, s2, s3,re;
	getline(cin, a); getline(cin, b); getline(cin, c);
	for(int i=0;i<a.length();i++)
	{
		if (i <= a.length() - 1)
			s1.push(a[i]-48);
		if (i <= b.length() - 1)
			s2.push(b[i]-48);
		if (i <= c.length() - 1)
			s3.push(c[i]-48);		
	}

	int jinwei=0;
	while(!s2.empty()||!s3.empty())
	{
		int t2,t3;
		if (s2.empty()) t2 = 0;
	
		else {
			t2 = s2.top(); s2.pop();
		}
		if (s3.empty()) t3 = 0;
		else {
			t3 = s3.top(); s3.pop();
		}
		int t1 = s1.top(); s1.pop();

		if (t1 == 0) t1 = 10;

		re.push((t2 + t3+jinwei) % t1);
		jinwei = (t2 + t3 + jinwei) / t1;
	}
	if (jinwei != 0)//最后一个相加的jinwei也要加进去
		re.push(jinwei);
	bool f = true;
	while (!re.empty()) {
		if (f&&re.top() == 0) {//无意义的零不要
			 re.pop(); continue;
		}		
		cout << re.top(); re.pop();f = false;
	}
    if(f)//0+0的情况
    cout<<0;
	
}
1047 编程团体赛 (20分)

//打印条件有点复杂

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
class Node {
public:
	int value,address,next;
};
int main() {
	int first, k, n;
	cin >> first >> n >> k;
	map<int, Node>m; vector<Node>v1,v2,v3;
	for (int i = 0; i < n; i++)
	{
		Node node;
		cin >> node.address >> node.value >> node.next;
		m[node.address] = node;		
	}
	for (int i = 0; i < n; i++)
	{
		if (first == -1) break;
		if (m.count(first)) {
			Node node = m[first];
			if (node.value < 0)
				v1.push_back(node);
			else if (node.value <= k && node.value >= 0)
				v2.push_back(node);
			else
				v3.push_back(node);
			first = m[first].next;
		}
	}
	for (int i = 0; i < v1.size(); i++)
	{
		printf("%05d %d ", v1[i].address, v1[i].value);
		if (i != v1.size() - 1)
			printf("%05d\n", v1[i + 1].address);
		else if(i==v1.size()-1&&v2.size()>0) 
			printf("%05d\n", v2[0].address);
        else if(i==v1.size()-1&&v2.size()==0&&v3.size()>0) 
			printf("%05d\n", v3[0].address);
        else
            printf("-1\n");     
	}
	for (int i = 0; i < v2.size(); i++)
	{
		printf("%05d %d ", v2[i].address, v2[i].value);
		if (i != v2.size() - 1)
			printf("%05d\n", v2[i + 1].address);
		else if(i==v2.size()-1&&v3.size()>0)
			printf("%05d\n", v3[0].address);
        else
            printf("-1\n");
	}
	for (int i = 0; i < v3.size(); i++)
	{
		printf("%05d %d ", v3[i].address, v3[i].value);
		if (i != v3.size() - 1)
			printf("%05d\n", v3[i + 1].address);
		else 
			printf("-1\n");
	}
	
}
1047 编程团体赛 (20分)
A-F D-F C-F B-T
1047 编程团体赛 (20分)
1047 编程团体赛 (20分)
1047 编程团体赛 (20分)
1047 编程团体赛 (20分)
1047 编程团体赛 (20分)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值