- 博客(21)
- 收藏
- 关注
原创 进制转换
/*将P进制数x转为十进制数y*/ int y=0,product=1,x,P; while(x!=0){ y = y + (x%10)*product; x = x/10; product = product*P; } /*将十进制数y转为Q进制数z*/ int z[40],num=0,y,Q; do{ z[num++]=y%Q;//num自增,跳出循环时已经自增1 y = y/Q;
2021-03-23 10:21:55
144
原创 牛客网 简单计算器
题目描述 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值。 输入描述: 测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔。没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出。 输出描述: 对每个测试用例输出1行,即该表达式的值,精确到小数点后2位。 示例1 输入 1 + 2 4 + 2 * 5 - 7 / 11 0 输出 3.00 13.36 #include<iostream> #inclu
2021-03-23 10:09:26
453
原创 括号匹配问题
#include<iostream> #include<cstdio> #include<algorithm> #include<string> #include <vector> #include<queue> #include<stack> using namespace std; stack<char> myStack; int main(){ string str; while(cin&
2021-03-23 09:31:53
226
原创 猫狗收容所(队列)
猫狗收容所 #include<iostream> #include<cstdio> #include<algorithm> #include<string> #include <vector> #include<queue> using namespace std; struct Animals { int number;//本身编号 int order;//进入次序 Animals(){} Anima
2021-03-22 22:11:20
245
原创 向量操作= =
int myArray[] = {1,2,3,4,5}; vector<int> myVector(myArray,myArray+5); int n = myVector.size(); myVector.pop_back(); myVector.push_back(6); myVector.insert(myVector.begin()+1,9); myVector.insert(myVector.begin(),myArray,myArray
2021-03-22 20:51:12
133
原创 子串计算
(某个题解的好方法,不是自己写的,还写不出来= =) 题目描述 给出一个01字符串(长度不超过100),求其每一个子串出现的次数。 输入描述: 输入包含多行,每行一个字符串。 输出描述: 对每个字符串,输出它所有出现次数在1次以上的子串和这个子串出现的次数,输出按字典序排序。 示例1 输入 10101 输出 0 2 01 2 1 3 10 2 101 2 #include <stdio.h> #include <string.h> #include <algorithm
2021-03-22 15:13:56
1867
原创 牛客网小白鼠排队(结构体排序)
#include<iostream> #include<cstdio> #include<algorithm> #include<string> using namespace std; const int MAXN = 1000+10; struct Mice{ int weight; string color; }; Mice m[MAXN]; bool comp(Mice x,Mice y){ if(x.weight>
2021-03-22 14:16:08
179
原创 KMP算法
#include <iostream> #include<algorithm> #include<cstdio> #include<cstdlib> #include<string> #include<stdio.h> #include<cstring> using namespace std; //KMP算法 const int MAXN = 100; int nextTable[MAXN]; void GetNex
2021-03-20 15:28:00
113
原创 查找方法大杂烩
#include <iostream> #include<algorithm> #include<cstdio> #include<cstdlib> using namespace std; const int MAXN = 1000+10; const int RANGE = 1e6; int a[MAXN]; int b[MAXN]; bool hashTable[RANGE];//散列查找 bool LinearSearch(int n,int t
2021-03-20 09:29:32
94
原创 查找
#include <iostream> #include<algorithm> #include<cstdio> #include<cstdlib> using namespace std; const int MAXN = 1000+10; int a[MAXN]; int b[MAXN]; int main() { int n; scanf("%d",&n); for(int i = 0;i < n; i
2021-03-19 23:55:37
115
原创 求乱序数列中的第k大元素
#include <iostream> #include<algorithm> #include<cstdio> #include<cstdlib> using namespace std; const int MAXN = 1000+10; int arr[MAXN]; int Partition(int left,int right){ int random = left + rand() % (right - left + 1); s
2021-03-19 23:39:35
155
原创 快速排序
#include <iostream> #include<algorithm> #include<cstdio> #include<cstdlib> using namespace std; const int MAXN = 1000+10; int arr[MAXN]; int Partition(int left,int right){ int random = left + rand() % (right - left + 1); s
2021-03-19 23:26:23
99
原创 北大oj1804
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include <stdio.h> using namespace std; const int MAXN = 1000+10; int temp[MAXN]; int arr[MAXN]; int number;//逆序数个数 //整合 void Combine(int left,int mid
2021-03-14 16:05:30
160
原创 归并排序
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include <stdio.h> using namespace std; const int MAXN = 1e6; const int RANGE = 5e5; int temp[MAXN]; int arr[MAXN]; //整合 void Combine(int left,int mid
2021-03-14 15:34:27
104
原创 杭电1425(unsolved)
#include #include #include #include #include <stdio.h> using namespace std; const int MAXN = 1e6; const int RANGE = 5e5; int number[MAXN]; int arr[MAXN]; //计数排序 int main(){ int n,m; while(scanf("%d%d",&n,&m)!= EOF){ memset(number,0,sizeof(num
2021-03-14 15:03:55
146
原创 成绩排序
题目描述 用一维数组存储学号和成绩,然后,按成绩排序输出。 输入描述: 输入第一行包括一个整数N(1<=N<=100),代表学生的个数。 接下来的N行每行包括两个整数p和q,分别代表每个学生的学号和成绩。 输出描述: 按照学生的成绩从小到大进行排序,并将排序后的学生信息打印出来。 如果学生的成绩相同,则按照学号的大小进行从小到大排序。 示例1 输入 3 1 90 2 87 3 92 输出 2 87 1 90 3 92 #include<bits/stdc++.h> //万能头
2021-03-13 10:38:53
478
原创 数字键盘
题目描述 按照手机键盘输入字母的方式,计算所花费的时间 如:a,b,c都在“1”键上,输入a只需要按一次,输入c需要连续按三次。 如果连续两个字符不在同一个按键上,则可直接按,如:ad需要按两下,kz需要按6下 如果连续两字符在同一个按键上,则两个按键之间需要等一段时间,如ac,在按了a之后,需要等一会儿才能按c。 现在假设每按一次需要花费一个时间段,等待时间需要花费两个时间段。 现在给出一串字符,需要计算出它所需要花费的时间。 输入描述: 一个长度不大于100的字符串,其中只有手机按键上有的小写字母 输出
2021-03-13 10:08:51
130
原创 打印日期
题目描述 给出年分m和一年中的第n天,算出第n天是几月几号。 输入描述: 输入包括两个整数y(1<=y<=3000),n(1<=n<=366)。 输出描述: 可能有多组测试数据,对于每组数据, 按 yyyy-mm-dd的格式将输入中对应的日期打印出来。 示例1 输入 2000 3 2000 31 2000 40 2000 60 2000 61 2001 60 输出 2000-01-03 2000-01-31 2000-02-09 2000-02-29 2000-03-01 20
2021-03-12 23:46:21
130
原创 打印题杭电2074
Sample Input 11 B A 5 @ W Sample Output AAAAAAAAA ABBBBBBBBBA ABAAAAAAABA ABABBBBBABA ABABAAABABA ABABABABABA ABABAAABABA ABABBBBBABA ABAAAAAAABA ABBBBBBBBBA AAAAAAAAA @@@ @WWW@ @W@W@ @WWW@ @@@ #include<iostream> #include<cstdio> using namespac
2021-03-12 22:18:02
389
原创 准备机试Day1
逆序数(例如1234的逆序数是4321) int Reverse(int number){ int reverseNumber = 0; while(number!=0){ reverseNumber *=10; reverseNumber += number%10; number /=10; } return reverseNumber; }
2021-03-12 20:12:54
75
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅