王道机试指南
分享机试指南的个人代码
「已注销」
这个作者很懒,什么都没留下…
展开
-
九度oj1201
#include<stdio.h>struct Node{ Node *lchild; Node *rchild; int c;}Tree[25];int loc=0;Node *creat(){ Tree[loc].lchild=Tree[loc].rchild=NULL; return &Tree[loc++];}Node *Insert(Node *...原创 2018-02-10 09:24:29 · 131 阅读 · 0 评论 -
九度oj 搬水果1107
/* n(1<=n<=10000),表示水果的种类数,第 i 个整数(1<=ai<=1000)是第 i 种水果的数目。39 1 20样例输出:15*/#include<stdio.h>#include<queue>using namespace std;priority_queue<int,vector<int>...原创 2018-02-10 19:46:10 · 209 阅读 · 0 评论 -
九度oj1019简单计算器
#include<stack>#include<stdio.h>using namespace std;char str[220];//保存表达式字符串int mat[][5]={//优先级矩阵,若mat[i][j] ==1,则表示i号运算符优先级大于j号运算符//运算符编码规则为+为1号,-为2号,*为3号,/为4号,人为添加在表达式首尾的标记运算符为0号 ...原创 2018-02-09 07:51:33 · 288 阅读 · 0 评论 -
二叉排序树
#include<stdio.h>int a[110];int loc;struct Node{ Node *lchild; Node *rchild; char c;}Tree[110];void PreOrder(Node *T){ printf("%d ",T->c); if(T->lchild)PreOrder(T->lchild); i...原创 2018-02-09 17:39:09 · 131 阅读 · 0 评论 -
二叉排序树--哪里错了,求解
#include<stdio.h>struct Node{ Node *lchild; Node *rchild; char c;}Tree[110];void PreOrder(Node *T){ printf("%d ",T->c); if(T->lchild) PreOrder(T->lchild); if(T->rchild) PreO...原创 2018-02-09 22:09:49 · 176 阅读 · 0 评论 -
二叉排序树--更正
#include<stdio.h>struct Node{ Node *lchild; Node *rchild; int c;}Tree[110];int loc=0;void PreOrder(Node *T){ printf("%d ",T->c); if(T->lchild) PreOrder(T->lchild); if(T->r...原创 2018-02-09 22:20:32 · 119 阅读 · 0 评论 -
九度oj1153括号匹配问题
#include<stdio.h>#include<stack>using namespace std;stack <int> s;char str[110];char ans[110];int main(){ while(~scanf("%s",str)){ int i; for(i=0;str[i];i++){ if(str...原创 2018-02-08 17:59:46 · 171 阅读 · 0 评论 -
sort
#include#includeusing namespace std;int main(){int i,n;int a[100];scanf("%d",&n);for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); for(i=0;i<n-1;i++) printf("%d ",a[i]); p原创 2018-01-27 08:13:01 · 195 阅读 · 0 评论 -
sort降序
#include#includeusing namespace std;bool cmp(int x,int y){return x>y;}int main(){int i,n,a[105];scanf("%d",&n);for(i=0;iscanf("%d",&a[i]);sort(a,a+n,cmp);for(i=0;i print原创 2018-01-27 08:28:55 · 1545 阅读 · 0 评论 -
成绩排序
/*姓名 年龄 成绩成绩 姓名 年龄3abc 20 99bcd 19 97bed 20 97bcd 19 97bed 20 97abc 20 99*/ #include#include#includeusing namespace std;struct E{ char name[101]; int age; int score; bool operato原创 2018-01-27 09:03:00 · 298 阅读 · 0 评论 -
特殊排序
//4//1 3 4 2//4//1 2 3//如果数组中只有一个数,当第一行将其输出后,第二行请输出"-1"。#include#includeusing namespace std;int main(){ int n,i; int a[1005]; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); s原创 2018-01-27 09:49:51 · 122 阅读 · 0 评论 -
字符串内排序
//输入一个字符串,长度小于等于200,然后将输出按字符顺序升序排序后的字符串。//bacd//abcd#include#include#includeusing namespace std;int main(){ char str[201]; int i,n; scanf("%s",str); sort(str,str+strlen(str)); pri原创 2018-01-27 14:05:29 · 280 阅读 · 0 评论 -
EXCEL排序
#include#include#includeusing namespace std;struct student{ char xue[7]; char name[9]; int score;}stu[100001];bool cmp1(student a,student b){ return strcmp(a.xue,b.xue)<0; }bool cmp2(原创 2018-01-27 21:03:19 · 247 阅读 · 0 评论 -
EXCEL排序总结
1struct E{}buf[101]; E相当于int buf 相当于acmp(buf a,buf b)这种写法就是错的 buf相当于是一个实例 而E才是是一个类型2strcmp返回只是判断 而不能拿来用具体的判断3N为0的情况要考虑到,在最后输入0 0就是结束输入 当N=0是,程序结束4题目的意思理解错了注意是当名字相同是考虑学号,比较学号它比较小,可以用原创 2018-01-27 22:19:20 · 178 阅读 · 0 评论 -
日期类问题总结题型
日期类几种:1、给出两个日期,求差值;2、给出一个日期,问你是这年的第几天;3、给出这天是某年的第几天,问你日期;4、给出一个日期,问你是星期几。原创 2018-01-27 22:38:55 · 262 阅读 · 0 评论 -
日期计算天数
#include#define ISYEAP(x) x%100!=0 && x%4==0 || x%400==0?1:0 //宏定义是否为闰年#define ABS(x) x<0?-x:x; //绝对值函数int dayOfMonth[13][2]={ 0,0, 31,31, 28,29, 31,31, 30,30, 31,31,原创 2018-01-28 13:37:30 · 531 阅读 · 0 评论 -
九度OJ 1432 叠筐
九度OJ 1432 叠筐题目大意: 在一条线上涂颜色,以前某一段的颜色可能被后来的覆盖。 你的任务是数数最后你可以看见多少种颜色 输入:x1 x2 c x1和x2分别代表段的两端,c代表颜色 解题思题目1432:叠筐时间限制:1 秒内存限制:128 兆特殊判题:否提交:5570解决:1290题目描述:把一个个大小差一圈的筐叠上去,使得从上往下原创 2018-01-30 16:39:45 · 187 阅读 · 0 评论 -
1069查找学生信息
#include#include#includeusing namespace std;struct Student{//表示学生个体的结构体 char no[100];//学号 char name[100];//姓名 int age;//年龄 char sex[5];//性别 bool operator< (const Student &A) const {//重载小于运算符原创 2018-01-31 10:11:59 · 368 阅读 · 0 评论 -
find x
#includeint main(){ int i,n,a[200];//a[i]范围为[0,10000] scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } int key; scanf("%d",&key); for(i=0;i<n;i++){ if(a[i]==key){ printf("%d\n",i原创 2018-02-05 13:00:06 · 195 阅读 · 0 评论 -
find x2
#includeint main(){ int i,n,hash[10001]={0};//a[i]范围为[0,10000] scanf("%d",&n); for(i=0;i<n;i++){ int tmp; scanf("%d",&tmp); hash[tmp]=1; } int key; scanf("%d",&key); if(hash[key]==1)原创 2018-02-05 13:00:42 · 406 阅读 · 0 评论 -
find x3
#includeint main(){ int i,n,a[200]; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } int key; scanf("%d",&key); for(i=n-1;i>=0;i--){ if(a[i]==key) break; } printf("%d\n",i);原创 2018-02-05 13:01:07 · 368 阅读 · 0 评论 -
find student information
#include#includeusing namespace std;struct student{ int id; char name[20]; char gender[5]; int age;};bool cmp(student A,student B){ return A.id<B.id;}int main(){ int n; student stu[10原创 2018-02-05 13:01:42 · 100 阅读 · 0 评论 -
find student information
#include#includeusing namespace std;struct student{ int id; char name[20]; char gender[5]; int age;};bool cmp(student A,student B){ return A.id<B.id;}int BiSearch(student stu[],int n,int原创 2018-02-05 13:02:11 · 123 阅读 · 0 评论 -
find student information
#include#include struct student{ char name[20]; char gender[5]; int age;}stu[1000];int main(){ int n; scanf("%d",&n); for(int i=0;i<1000;++i) stu[i].age = -1; int id,age; char name[20],原创 2018-02-05 13:02:45 · 146 阅读 · 0 评论 -
find student information
#include#include#includeusing namespace std;struct student{ char id[20]; char name[20]; char gender[5]; int age;};bool cmp(student A,student B){ return strcmp(A.id,B.id)<0;}int BiSearch(原创 2018-02-05 13:03:12 · 140 阅读 · 0 评论 -
九度Oj 1173
/*输入有多组数据,每组输入n,然后输入n个整数,再输入m,然后再输入m个整数(1<=m<=n<=100)。51 5 2 4 332 5 6YESYESNO*/#includeint main(){ int a[101],find[101]; int n,m,i,j; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",原创 2018-02-05 13:28:41 · 297 阅读 · 0 评论 -
今年暑假不AC
#include#includeusing namespace std;struct program{ int Ti_s;//第i个节目开始 int Ti_e;//和结束时间}pro[101];bool cmp(program A,program B){ return A.Ti_e<B.Ti_e;//按照结束时间 }int main() { int i,n;//n小于100原创 2018-02-05 15:50:30 · 245 阅读 · 1 评论 -
FIND
/*输入有多组数据,每组输入n,然后输入n个整数,再输入m,然后再输入m个整数(1<=m<=n<=100)。51 5 2 4 332 5 6YESYESNO*/#includeint main(){ int i,j,n,hash[100]={0},find[100]; int tmp[100]; while(scanf("%d",&n)!=EOF){//5 for(i=原创 2018-02-05 17:31:43 · 146 阅读 · 0 评论 -
迷瘴
/* 31 100 101002 100 2420 303 100 2420 20 30样例输出:0 0.00100 0.20300 0.23*/ #include#includeusing namespace std;int main(){ int C; scanf("%d",&C);//测试数据的组数; while(C--){//3 int V,n;原创 2018-02-06 11:45:31 · 156 阅读 · 0 评论 -
FatMouse's Trade
/*5 3 7 2 4 3 5 2 20 3 25 1824 1515 10-1 -113.333结果保留3位小数 31.500*/#include#includeusing namespace std;struct exchange{ double J;//javaBean double F;//FatFood double val原创 2018-02-06 14:08:11 · 154 阅读 · 0 评论 -
背包问题
#include#include using namespace std;struct bag{ int v;//每个物品的单位重量的价值 int w;//每个物品的重量}bagg[10];bool cmp(bag x,bag y){ return x.v>y.v;}int main(){ int n;//n组测试数据 int s; int m;//s个物品 容纳的原创 2018-02-06 15:57:23 · 120 阅读 · 0 评论 -
特殊排序
#include#includeusing namespace std;int main(){ int N,i,a[101]; scanf("%d",&N); for(i=0;i<N;i++) scanf("%d",&a[i]); sort(a,a+N); printf("%d",a[0]); for(i=1;i<N-1;i++) pri原创 2018-02-06 18:10:36 · 136 阅读 · 0 评论 -
成绩排序
#include#include#includeusing namespace std;struct student{ char name[101]; int age; double grade; bool operator <(const student &b) const{ if(grade!=b.grade) return grade<b.grade; else原创 2018-02-06 18:19:02 · 193 阅读 · 0 评论 -
EXCEL排序
#include#include#includeusing namespace std;struct E{ char id[10]; char name[10]; int score;}stu[100001];bool cmp1(E a,E b){ return strcmp(a.id,b.id)<0;}bool cmp2(E a,E b){//按姓名非递减排序 in原创 2018-02-06 22:29:36 · 182 阅读 · 0 评论 -
+-
#include#include#includeusing namespace std;//AC;stack S1,S2;int Abs(int x){ return x>0? x:-x;}int main(){ int i; char str1[5001],str2[5001]; while(~scanf("%s%s",str1,str2)){ if(strlen(原创 2018-02-07 11:53:38 · 153 阅读 · 0 评论 -
打印极值点下标
/*31010 12 12 11 11 12 23 24 12 121512 12 122 112 222 211 222 221 76 36 31 234 256 76 76 1512 14 122 112 222 222 222 221 76 36 31 234 256 76 73123456780 72 3 4 5 6 10 120 2 3 10 12 1原创 2018-02-07 11:54:12 · 292 阅读 · 0 评论 -
输出梯形
#includeint main(){ int i,j,h; while(~scanf("%d",&h)){ for(i=1;i<=h;i++){ for(j=1;j<=2*(h-i);j++) printf(" "); for(j=1;j<=h+2*(i-1);j++) printf("*"); printf("\n");原创 2018-02-07 11:54:47 · 178 阅读 · 0 评论 -
今天是今年第几天
#include#define ISYEAP(x) x%100!=0 &&x%4==0 || x%400==0int Day[13] ={0,31,28,31,30,31,30,31,31,30,31,30,31};int main(){ int Y,M,D,count; while(~scanf("%d%d%d",&Y,&M,&D)){ count=0; for(int i=原创 2018-02-07 11:55:18 · 304 阅读 · 0 评论 -
今天是今年第几天
#include#define ISYEAP(x) x%100!=0 && x%4==0 ||x%400==0 ?1 :0int DayOfMonth[13][2]={ 0,0, 31,31,//1 28,29,//2 31,31,//3 30,30,//4 31,31,//5 30,30,//6 31,31,//7 31,31,//8 30,30,//9 31,31,/原创 2018-02-07 11:55:52 · 1770 阅读 · 1 评论 -
谁是你的潜在朋友
#includeint main(){ int N,M,P[201],fri[201]={0}; while(~scanf("%d %d",&N,&M)){//N个读者,M本书 for(int i=1;i<=N;i++) { scanf("%d",&P[i]);//第i个人读了第P[i]本书 ++fri[P[i]];//该书有几个人阅读 } for(in原创 2018-02-07 11:56:30 · 192 阅读 · 0 评论