第一次上手PAT的甲级题目,瑟瑟发抖(英语不好对着题目愣了半天) 这一题的要点是使用sort函数. 使用sort函数必须使用 #include <algorithm> using namespace std; 一开始我是准备在结构体内同时储存局部排名和总体排名的,但是书上的做法空间复杂度比我的好多了: 只需要在结构体内存储局部排名,在最后输出时生成具体排名,而且还解决了困扰我的名次相同的问题. 还是对sort函数不是非常熟悉,所以适应的时间长了点. #include <cstdio>…
这一题本来不应该有什么问题的,我很快写出来了,在dev c++里面运行也正常.但是放到pat以后出现了问题.更换了c/c++都不行通过编译. #include <cstdio> #include <cstring> int main(){ ]; gets(str); ,k=,let[]; while(str[i]!='\0'){ if(str[i]==' '){ let[k++]=i; } i++; } let[k++]=strlen(str); ;i<k;i++){ ){…
lc88 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int i = m - 1, j = n - 1; int p = m + n - 1; while(i >= 0 && j >= 0){ nums1[p--] = nums1[i] > nums2[j] ? nums1[i--] : nums2[j--]; } if(j >= 0){ for (int…
剑指 Offer 09. 用两个栈实现队列 用两个栈实现一个队列.队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能.(若队列中没有元素,deleteHead 操作返回 -1 ) class CQueue { Stack<Integer> stackA, stackB; public CQueue() { stackA = new Stack<Integer>(); stackB = new S…
剑指 Offer 06. 从尾到头打印链表 class Solution { public int[] reversePrint(ListNode head) { Stack<Integer> stack = new Stack<>(); while(head != null){ stack.push(head.val); head = head.next; } ArrayList<Integer> list = new ArrayList<>(); whi…
剑指 Offer 05. 替换空格 class Solution { public String replaceSpace(String s) { StringBuilder str = new StringBuilder(s); int p1 = str.length() - 1; for(int i = 0; i <= p1; i++){ if(str.charAt(i) == ' ') str.append(" "); } int p2 = str.length() - 1…
剑指 Offer 03. 数组中重复的数字 哈希表/set class Solution { public int findRepeatNumber(int[] nums) { HashSet<Integer> set = new HashSet<>(); for(int num : nums){ if(set.contains(num)) return num; set.add(num); } return -1; } } 思路:利用set的特性 原地置换 class Solut…
大家好,我是 程序员小熊 ,来自 大厂 的程序猿.相信绝大部分程序猿都有一个进大厂的梦想,但相较于以前,目前大厂的面试,只要是研发相关岗位,算法题基本少不了,所以现在很多人都会去刷 Leetcode 来保持手感,但有不少人反馈刷题效率很低,今天笔者抽空整理了 三份 分别来自 谷歌的高畅.前阿里的霜神和灵魂机器 的刷题手册,以供大家参考,希望对大家无有所帮助. 一. A LeetCode Grinding Guide (C++ Version) 作者:谷歌的高畅 背景:作者在美国卡内基梅隆大学攻读…
刷题链接:https://www.patest.cn/contests/pat-a-practise 1001 #include <iostream> #include <stdio.h> using namespace std; ]; int main() { int a,b,sum,index; while(scanf("%d%d",&a,&b)!=EOF){ sum=a+b; ){ printf("-"); sum=-s…
重拾经典 本科生涯结束了,在大学做的ACM竞赛现在基本忘的差不多了.USACO作为一个经典的题库,本来是面向OI选手的,但是由于题目质量很高所以受到大家的好评,所以我这次就从它开始我的刷题之路吧. 由于题目都是英文的,所以我觉得对自己的英语学习应该也会有点帮助. 我将会把所有我解决的题目用解题报告的形式发布到我的博客,与大家分享我的解题思路. 欢迎大家与我联系讨论,相互学习共同成长.…