[PAT]入门Day1

9月11日要考个PAT甲级,也算是为了机试做准备吧,记录一下从今天起每一天写的题的链接,便于后期复习,也方便大家一起学习~

第一题 B1001害死人不偿命的(3n+1)猜想

答题链接https://pintia.cn/problem-sets/994805260223102976/problems/994805325918486528

#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    
    
    int n;
    scanf("%d", &n);

    int count = 0;
    while (n != 1) {
    
    
        if (n % 2 == 0) {
    
    
            n /= 2;
        }
        else {
    
    
            n = (3 * n + 1) / 2;
        }
        count++;
    }
    printf("%d\n", count);
    return 0;
}

第二题 B1032 挖掘机技术哪家强

答题链接https://pintia.cn/problem-sets/994805260223102976/problems/994805289432236032

有2分死也得不到,不知道哪种情况没考虑到,有没有大神帮忙解答啊?

#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>

const int MAXN = 100010;
// 段错误:原来设的1000,但是学校个数可能很多,参数人数最多10的五次方,那么学校个数的最大值也要是10的五次方
int schoolsum[MAXN] = {
    
    0};

int Findmax(int arr[]) {
    
    
	int max = 0;
	int index = -1;
	for (int i = 0; i < MAXN; i++) {
    
    
		if (arr[i] > max) {
    
    
			max = arr[i];
			index = i;
		}
	}
	return index;
}

int main() {
    
    
	int n;
	scanf("%d", &n);
	while (n--) {
    
    
		int school, scores;
		scanf("%d %d", &school, &scores);
		schoolsum[school] += scores;
	}
	printf("%d %d", Findmax(schoolsum), schoolsum[Findmax(schoolsum)]);
}

3-1练习题

答题链接http://codeup.hustoj.com/contest.php?cid=100000575

问题 A: 剩下的树

继一年前上计组课之后,再一次用VS进行断点调试。。
之前得debug都是疯狂读代码试错,直到问学长一个系统工程上面得问题,学长说“设个断点”,我一脸懵逼“啥是断点”。
再接再厉啦!!继续冲冲冲,快乐学coding。

就看了一道简单的~

#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>

using namespace std;
const int MAXL = 10010;
int tree[MAXL] = {
    
     1 };



int main() {
    
    
	for (int i = 0; i < MAXL; i++) {
    
    
		tree[i] = 1;
	}
	int L, M, left, right, count = 0;
	while (scanf("%d %d", &L, &M) != EOF) {
    
    
		if (L == 0 && M == 0) {
    
    
			break;
		}
		while (M--) {
    
    
			scanf("%d %d", &left, &right);
			for (int i = left; i <= right; ++i) {
    
    
				tree[i] = 0;
			}
		}
		
		for (int i = 0; i <= L; ++i) {
    
    
			if (tree[i] == 1) {
    
    
				count++;
			}
		}
		printf("%d\n", count);
		for (int i = 0; i < MAXL; i++) {
    
    
			tree[i] = 1;
		}
		count = 0;
	}
	return 0;
}

问题 D: 比较奇偶数个数

感谢世界上存在这种简单题,让小白有勇气继续学下去。。

#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>

int main() {
    
    
	int n, num;
	while (scanf("%d", &n) != EOF) {
    
    
		int dul = 0;
		for (int i = 0; i < n; ++i) {
    
    
			scanf("%d", &num);
			if (num % 2 == 0) {
    
    
				dul++;
			}
		}
		if (dul > (n - dul) ){
    
    
			printf("NO\n");
		}
		else {
    
    
			printf("YES\n");
		}
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44145782/article/details/119086992