
面试编程训练
一般面试时会有一些编程题考察编程基础能力,本专栏提供一些难度适中的编程题以及题解,适用于面试候选人训练。
AI记忆
这个作者很懒,什么都没留下…
展开
-
1050. String Subtraction (20)
简单的考察建立查询表 题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1050#include#include #include #include #include #include #include #include #include using namespace std;#define MAX 1000i原创 2013-03-10 20:20:10 · 2957 阅读 · 2 评论 -
1051. Pop Sequence (25)
考察数据结构Stack的push跟pop操作 题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1051#include#include #include #include #include #include #include #include #include using namespace std;int mai原创 2013-03-10 20:22:59 · 3298 阅读 · 0 评论 -
1052. Linked List Sorting (25)
考察链表的知识,以及排序题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1052#include#include #include #include #include #include #include #include #include using namespace std;typedef struct Nod原创 2013-03-10 20:24:46 · 3306 阅读 · 4 评论 -
1053. Path of Equal Weight (30)
考察链表,排序,以及深度搜索题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1053#include#include #include #include #include #include #include #include #include using namespace std;int N, M, T;typ原创 2013-03-10 20:26:28 · 2753 阅读 · 1 评论 -
1012. The Best Rank (25)
考察结构体排序#include#include#include#include#include#include#include#includeusing namespace std;int n;//studentint m;//querytypedef struct Node{ string name; int grade[4]; int bestRank; i原创 2013-03-10 20:37:26 · 4617 阅读 · 12 评论 -
1013. Battle Over Cities (25)
考察并查集#include#include#include#include#include#include#include#includeusing namespace std;int n;//number of cityint m;//number of edgeint k;//number of querytypedef struct Edge{ int v;原创 2013-03-10 20:38:37 · 2795 阅读 · 0 评论 -
1014. Waiting in Line (30)
考察排队#include#include#include#include#include#include#include#includeusing namespace std;int N;// (<=20, number of windows)int M;// (<=10, the maximum capacity of each line inside the yell原创 2013-03-10 20:40:13 · 3578 阅读 · 0 评论 -
1023. Have Fun with Numbers (20)
考察数字字符串操作#include#include#include#include#include#include#include#includeusing namespace std;void GetCntTable(string a, vector& cntTable){ cntTable.assign(10, 0); for(int i = 0; i < a.s原创 2013-03-10 20:41:30 · 2980 阅读 · 0 评论 -
1024. Palindromic Number (25)
考察数字字符串操作#include#include#include#include#include#include#include#includeusing namespace std;string Reverse(string a){ string ans; for(int i = 0; i < a.size(); ++i) ans.insert(ans.beg原创 2013-03-10 20:42:37 · 2539 阅读 · 0 评论 -
1025. PAT Ranking (25)
考察结构体排序以及合并操作#include#include#include#include#include#include#include#includeusing namespace std;typedef struct Node{ string registrition_number; int grade; int location_number; int l原创 2013-03-10 20:44:06 · 2441 阅读 · 0 评论 -
1026. Table Tennis (30)
考察模拟队列等待这道题目的vip用户以及vip桌子的存在,使得要考虑的case数多了一些另外这个题目的playtime是有截断的#include#include#include#include#include#include#include#includeusing namespace std;typedef struct Node{ int arrive, p原创 2013-03-10 20:46:30 · 3635 阅读 · 0 评论 -
1040. Longest Symmetric String (25)
考察最长对称连续子序列可先插入特殊字符,然后枚举每一个中心点#include#include#include#define Max 10000int dp[2*Max+1];char str[Max];int mmax(int a, int b){ if(a > b) return a; else return b;}int main(){ while(get原创 2013-03-10 21:07:51 · 2589 阅读 · 1 评论 -
1041. Be Unique (20)
考察查询表#include#includetypedef struct lottery{ int cnt; int index; lottery(int _cnt = 0, int _index = 0):cnt(_cnt),index(_index){}}Lottery;#define MAX 10000int main(){ int N; while( scanf原创 2013-03-10 21:08:42 · 1773 阅读 · 0 评论 -
1042. Shuffling Machine (20)
考察字符串操作#includevoid OutputWord(int a){ int flag = a/13; if(0 == flag) printf("S"); else if(1 == flag) printf("H"); else if(2 == flag) printf("C"); else if(3 == flag) printf("D"); el原创 2013-03-10 21:10:33 · 2307 阅读 · 1 评论 -
1043. Is It a Binary Search Tree (25)
考察建立二叉树,以及树的遍历#include#include#includetypedef struct Node{ int key; Node* left; Node* right; Node(Node* _l = NULL, Node* _r = NULL, int _k = -1) :left(_l), right(_r),key(_k){};}Node;vo原创 2013-03-10 21:12:03 · 2711 阅读 · 4 评论 -
1044. Shopping in Mars (25)
考察二分#include#includevoid FindBest(std::vector& sum, int m, int i, int& j, int& tmpSum){ //j = tmpSum = -1; //binary search int l = i; int r = (int)sum.size()-1; //int all = sum[l]-sum[r];原创 2013-03-10 21:12:54 · 2313 阅读 · 0 评论 -
1045. Favorite Color Stripe (30)
考察最长非连续子序列,有点变种#include#include#include#includeusing namespace std;int n, m, l;typedef struct Node{ int len, pre;}Node;int main(){ while(scanf("%d",&n)!=EOF) { scanf("%d",&m); vect原创 2013-03-10 21:14:05 · 2799 阅读 · 0 评论 -
1047. Student List for Course (25)
考察倒排索引注意如果用string的话会超时,因为string的copy时间以及比较时间都要比char数组的相应操作更耗时#include#include#include#includetypedef struct Student { char name[20];}Student;std::vector sVec;bool cmp(int s1, int s2){原创 2013-03-10 21:17:56 · 2898 阅读 · 0 评论 -
1048. Find Coins (25)
考察查询表#include#include#define FaceMax 1000int main(){ int n, m; while(scanf("%d%d",&n,&m)!=EOF) { //input std::vector coins; coins.assign(FaceMax+1, 0); while(n--) { int tmp;原创 2013-03-10 21:18:50 · 2217 阅读 · 0 评论 -
1001. A+B Format (20)
字符串模拟数字操作#include#include//using namespace std;int main(){ int a, b; while(scanf("%d%d",&a,&b)!=EOF) { int ans = a+b; int flag = 1;//1 nonnegtive; 0 negtive if(ans < 0) flag = 0, ans =原创 2013-03-10 21:22:07 · 3813 阅读 · 0 评论 -
1002. A+B for Polynomials (25)
数组模拟多项加法#include#include#include#define MAX 1000double p[MAX+1];int main(){ int aNum; while( scanf("%d", &aNum) != EOF ) { //initial memset(p, 0, sizeof(p[0])*(MAX+1)); //input a原创 2013-03-11 09:05:45 · 4050 阅读 · 2 评论 -
1003. Emergency (25)
考察最短路,以及相同最短路存在时的额外信息最优选择#include#include#define INF 0x6FFFFFFFtypedef struct Node{ int nPath; int call; int dis;}Node;std::vector city;std::vector> map;std::vector visit;std::vector t原创 2013-03-11 09:06:12 · 4160 阅读 · 0 评论 -
1004. Counting Leaves (30)
考察树结构的简单存储以及遍历搜索#include #include #include int n, m;std::vector> edge;std::vector BFS(int s){ std::queue> q; q.push(std::make_pair(s, 0)); int cur_step = 0; std::vector ans; int cnt = 0;原创 2013-03-11 09:06:31 · 4328 阅读 · 5 评论 -
1005. Spell It Right (20)
考察字符串模拟数字,以及查询表#include#include#includechar g_WordTable[10][100] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};void OutputWordTable(){ int cnt =原创 2013-03-11 09:06:57 · 2807 阅读 · 0 评论 -
1006. Sign In and Sign Out (25)
考察以时间为核心的事件模拟#includetypedef struct person{ char name[20]; int in; int out;}Person;int main(){ int m; while( scanf("%d", &m) != EOF ) { Person p_in, p_out, tmp; int h1, h2, m1, m2,原创 2013-03-11 09:07:11 · 2621 阅读 · 1 评论 -
1007. Maximum Subsequence Sum (25)
最大连续子序列和#include#includeint k;typedef struct Node{ int num; int start; int sum;}Node;std::vector d;int main(){ while(scanf("%d",&k)!=EOF) { d.resize(k); for(int i = 0; i < k; ++i)原创 2013-03-11 09:07:28 · 3099 阅读 · 0 评论 -
1008. Elevator (20)
考察以时间cost为核心的电梯时间模拟#includeint main(){ int n; while(scanf("%d",&n) != EOF) { int floorNow = 0; int sum = 0; while(n--) { int request; scanf("%d",&request); if(request > floorN原创 2013-03-11 09:07:41 · 2307 阅读 · 0 评论 -
1009. Product of Polynomials (25)
数组模拟多项式乘法#include#include#includetypedef struct Node{ double sum; int e;}Node;#define MAX 3000int main(){ int n1, n2; while(scanf("%d",&n1)!=EOF) { std::vector a(n1); for(int i = 0;原创 2013-03-11 09:07:57 · 3235 阅读 · 0 评论 -
1015. Reversible Primes (20)
考察素数以及非10进制到10进制数的转化#include#include#includeint ReverseNumber(int N, int D){ int sum = 0; do { sum = sum*D + N%D; N /= D; }while(N != 0); return sum;}bool IsPrime(int n){ //specia原创 2013-03-11 09:08:24 · 3926 阅读 · 0 评论 -
1016. Phone Bills (25)
参考自:考察以时间为核心的电话账单事件模拟以及统计#includeusing namespace std;#include#include#includestruct Call{ string name; int month; int date; int hour; int minute; int total; string status;};int原创 2013-03-11 09:08:35 · 3627 阅读 · 0 评论 -
1017. Queueing at Bank (25)
参考自:考察排队事件的模拟#include#include#includeusing namespace std;struct window{ int mm; int hh; int ss; bool operator<(const window& a)const { if(hh>a.hh) return tru原创 2013-03-11 09:09:21 · 3768 阅读 · 1 评论 -
1018. Public Bike Management (30)
考察最短路,以及记录相同长度最短路,然后遍历选择最优最短路#include#include#include#includeusing namespace std;#define INF 0x6FFFFFFFint Cmax, n, Sp, m;typedef struct Edge{ int v, dis; Edge(int _v, int _dis):v(_v),dis原创 2013-03-11 09:09:30 · 4797 阅读 · 0 评论 -
1019. General Palindromic Number (20)
考察回文以及任意进制数的转化#include#includevoid GetReverseNumberBaseD(int N, int D, std::vector& a){ do { int temp = N%D; a.push_back(temp); N /= D; }while(N != 0);}bool IsPalindromic(const std::v原创 2013-03-11 09:09:36 · 1965 阅读 · 0 评论 -
1020. Tree Traversals (25)
考察树的建立,以及树的遍历#include#include#include#includetypedef struct Node{ int value; Node* left; Node* right; Node(Node* _left = NULL, Node* _right = NULL, int _value = -1) :left(_left),right(_r原创 2013-03-11 09:09:54 · 2478 阅读 · 1 评论 -
1021. Deepest Root (25)
考察并查集以及树的搜索#include#include#include#include#include//#includestd::vector visited;std::vector step;std::vector> edge;std::vector p;int n;int BFS(int s){ visited.assign(n+1, false); std:原创 2013-03-11 09:10:02 · 2560 阅读 · 0 评论 -
1022. Digital Library (30)
考察倒排索引#include#include#include#include#include#includeusing namespace std;int main(){ int n; while(scanf("%d",&n)!=EOF) { //build map map> queryMap[5]; while(n--) { getchar();原创 2013-03-11 09:10:17 · 3456 阅读 · 2 评论 -
1027. Colors in Mars (20)
考察查询表以及求余分位#include#includechar g_CharTable[13] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C'};void OutPutIntVector(const std::vector& a){ int size = (int)a.size(); for(原创 2013-03-11 09:10:24 · 1932 阅读 · 0 评论 -
1028. List Sorting (25)
考察结构体排序#include#include#include#includetypedef struct Student{ int id; char name[20]; int g;}Student;int C;bool cmp(Student a, Student b){ if(C == 1) return a.id < b.id; else if(C原创 2013-03-11 09:10:30 · 1990 阅读 · 1 评论 -
1029. Median (25)
考察合并序列的中位数#include#includeint main(){ int n1, n2; while(scanf("%d",&n1)!=EOF) { std::vector a, b; for(int i = 0; i < n1; ++i) { int tmp; scanf("%d",&tmp); a.push_back(tmp); }原创 2013-03-11 09:10:34 · 2407 阅读 · 0 评论 -
1030. Travel Plan (30)
考察最短路及其路径记录#include #include #include #include using namespace std;#define INF 0x6FFFFFFFtypedef struct Node{ int dis, cost, path; Node(){dis=INF; cost=INF; path=-1;}}Node;typedef struct原创 2013-03-11 09:10:43 · 2729 阅读 · 0 评论