- 博客(37)
- 收藏
- 关注
原创 Merge Two Sorted List
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { if(NULL == l1) return l2; if(NULL == l2) return l1; ListNode* head=NULL; // head of the list to return // find f
2017-03-30 22:36:05 226 1
原创 Delete Node in a Linked List 删除指针指向的元素
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: void deleteN
2017-03-28 21:08:32 365
原创 leetcode 判断简单链表是否存在循环
/*struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};*/class Solution {public: bool hasCycle(ListNode *head) { ListNode*
2017-03-28 20:45:57 367
原创 02-线性结构4 Pop Sequence
#include #include #include #include #include using namespace std;int main(){ int M,N,K; cin>>M>>N>>K; while(K--) { //用数组存储数字序列 vector numbers; for(int i
2017-03-25 23:08:26 239
原创 线性表的数组表示
抽象数据类型 linearList// abstract class linearList// abstract data type specification for linear list data structure// all methods are pure virtual functions#ifndef linearList_#define linearList_#inc
2017-03-25 17:11:37 772
原创 ducci序列 Uva1594
#include #include #include #include using namespace std;int main(){ int N;//问题数 cin>>N; while(N--) { int number;//数字的数量 cin>>number; vectorin
2017-03-22 21:39:13 365
原创 习题5-6 对称轴 UVA1595
#include #include #include using namespace std;const int MAX=100000000;//用一个vector到int的字典来存储所有的点,y值作为Key,相同y值的点被存入同一个vector里。//判断时,先计算第一个key值下的所有数的平均值,然后将之后的Key值下的平均值与它比较,只要有一个不相同则输出NO。/
2017-03-22 21:08:33 254
原创 高精度阶乘
#include #include #include using namespace std;const int MAX=100000000;int main(){ int N; cin>>N; vector result; while(N) { if(result.empty()==1) result.p
2017-03-17 20:20:02 257
原创 大数乘法(套用紫书数据结构,时间花费长无法AC)
#include#include#include#include#include #include #include using namespace std;struct BigInteger { static const int BASE = 100000000; static const int WIDTH = 8; vector s; BigInteger
2017-03-16 23:29:24 390
原创 大数乘法
#include#includeusing namespace std;char c1[10005];void muti(char *a1, char*b1){ int lena1, lenb1; lena1 = strlen(a1); //测长度 lenb1 = strlen(b1); int a[10005] = { 0 }, b[10005] = { 0 }, c[1000
2017-03-16 23:27:41 212
原创 大数加法
#include#include#include#include#include #include using namespace std;struct BigInteger { static const int BASE = 100000000; static const int WIDTH = 8; vectorint> s; Big
2017-03-15 23:12:54 200
原创 例题5-6 团体队列 Uva540
#include #include #include using namespace std;const int maxt=1000+10;int main(){ int t,kase=0; while(scanf("%d",&t)==1&&t) { printf("Scenario #%d\n",++kase); map tea
2017-03-11 19:14:37 232
原创 例题 5-5 集合栈计算机 Uva 12096
#include #include #include #include #include #include #include using namespace std;const int maxn=10000;typedef set Set;map IDcache;vector Setcache;#define ALL(x) x.begin(),x.end()#define
2017-03-11 17:28:20 322
原创 快速模算法 A^BmodC
//模指数运算#include #include #include using namespace std;int main(){ //输入; int b; cin >> b; int n; cin >> n; int m; cin >> m; //二进制转换 int q = n; int k = 0; deque numbers; while (q != 0
2017-03-10 20:38:40 1622
原创 最小公倍数
#include int main(){ long long int a, b; std::cin >> a; std::cin >> b; if (a<b) { int temp = a; a = b; b = temp; } long long int s; long long int t1 = a; long long int t2 = b; while
2017-03-10 20:33:37 272
原创 最大公约数
#include int main(){ long long int a, b; std::cin >> a; std::cin >> b; long long int s; while (b != 0) { s = a; a = b; b = s%b; } std::cout << a; return 0;}辗转相除法
2017-03-10 20:32:24 177
原创 N阶乘MOD P
#include using namespace std;int mod(long long int n,long long int p){ if (n == 0) return 1; else return (mod(n - 1, p)*n%p) % p;}int main(){ long long int n,p; cin>>n>>p; cout<<mod(n,
2017-03-10 20:31:10 1050
转载 链式表实现模板
typedef struct LNode *PtrToLNode;struct LNode { ElementType Data; PtrToLNode Next;};typedef PtrToLNode Position;typedef PtrToLNode List; /* 查找 */#define ERROR NULL Position Find( List
2017-03-10 19:55:58 242
原创 习题4-5 IP网络 UVa 1590
#include #include #include #include #include using namespace std;string binary(const unsigned int val,string s){ for(int i = 7; i >= 0; i--) { if(val & (1 << i)) s.p
2017-03-10 19:27:49 290
原创 习题 4-8 特别困的学生 uva12108
#include #include #include using namespace std;vector students,temp;//1代表睡觉vector Avector,Bvector,Cvector;bool initial(){ int n; cin>>n; if(!n) return 0; else {
2017-03-09 22:58:41 262
原创 线性表的顺序存储实现
#include typedef struct LNode *List;typedef struct{ ElementType Data[MAXSIZE]; int Last;} LNode;//初始化顺序表List MakeEmpty(){ List PtrL; PtrL=(List)malloc(sizeof(LNode)); PtrL->
2017-03-08 17:30:22 242
原创 习题4-2 正方形
//注意输出格式#include #include #include #include #include #include #define maxn 100010using namespace std;void process(int n,int problemnumber){ //先对每个点是否存在先左或向下的边做标记 vector>> s; vecto
2017-03-06 17:25:48 451
原创 习题4-4 骰子涂色
#include #include #include #include #include #include #define maxn 100010using namespace std;//一共9种可能的旋转方式//竖直轴顺时针90string turn1(string a){ string b=a; b[4]=a[2]; b[2]=a[3];
2017-03-05 21:38:58 425
原创 习题 4-1 象棋
#include #include #include #include #include #include #define maxn 100010using namespace std;int Gx,Gy,Rx,Ry,Hx,Hy,Cx,Cy;void printChessboard(int chessboard[][11],int m=11,int n=11){ for
2017-03-05 19:37:56 492
原创 例题4-2 刽子手游戏
#include #include #include #include #include #include #define maxn 100010using namespace std;int main(){ int number; string word; string guess; while(cin>>number>>word>>guess
2017-03-04 18:19:25 362
原创 习题3-11 换低档装置
同样没写重复多次输入的那层循环。#include #include #include #include #include #include #define maxn 100010using namespace std;int main(){ string A,B; cin>>A>>B; A.push_back('0');//短数组最终移动出长数组才
2017-03-03 22:02:35 457
原创 习题 3-9 子序列
这个只写了判断一次的程序,没有加多次输入的循环。思想就是先在B序列里找A[0]对应的字母,找到后(找不到输出not,中断循环)标记这个位置,下个对应的字母必须从这个位置之后找才有效,以此类推。用了标准库里面的find函数,记得加头文件。#include #include #include #include #include #include #define maxn 100010us
2017-03-03 21:05:21 326
原创 习题3-5 puzzle
吐个槽,这题真是各种坑。#include #include #include #include #include using namespace std;int main(){ vector puzzle; string temp; int count=1; outside: puzzle.clear();// while(getline(ci
2017-03-03 19:38:13 230
原创 习题3-4 周期串
1.周期的表达方式 %取余2.每两个输出间空行 while(n--) if(n) printf("\n")#include #include #define maxn 81char s[maxn];int main(){ int n; scanf("%d",&n); int first=1; while(n--) {
2017-03-02 21:45:33 334
原创 习题3-3 数数字
#include #include int main(){ int m; scanf("%d",&m); for(int times=0;times<m;times++)//题目要求一般都是要输入好几个数字 { int counts[10]={0,0,0,0,0,0,0,0,0,0}; char numbers[6];
2017-03-02 20:18:28 532
原创 习题3-2 分子量(字符+数字)
#include #include #define maxn 81char s[maxn];int main(){ int t; scanf("%d",&t); for(int i=0;i<t;i++) { scanf("%s",s); int len=strlen(s); double tempmass=0
2017-03-01 23:32:26 350
原创 习题3-1 score
#include #include #define maxn 81char s[maxn];int main(){ //input n int n=0; scanf("%d",&n); //input n times for(int i=0;i<n;i++) { scanf("%s",s); int len=
2017-03-01 21:33:32 305
原创 第三章例题 最小生成元(逐位的写法)
#include #include /* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char** argv) { //输入n int n=0; scanf("%d",&n); //暴力查找符
2017-03-01 16:29:22 576
原创 第三章例题 最小生成元——逐位的写法
#include #include /* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char** argv) { //输入n int n=0; scanf("%d",&n); //暴力查找符
2017-03-01 16:26:51 377
原创 第三章例题 回文词与镜像词
#include #include #define maxn 100char s[maxn];int main(){ //输入一个字符串s memset(s,' ',sizeof(s)); while(scanf("%s",s)==1) { //判断它是否为回文串 //倒序字符串判断两字符串是否相等即可 //
2017-02-28 20:45:51 293
原创 开灯问题
#include #include #define maxn 1010int a[maxn];int main(){ memset(a,0,sizeof(a)); int n,k; scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) a[i]=1; for (int i=2;i<=k;i++)
2017-02-28 19:39:43 297
原创 每日打卡签到 连续日期数问题
#include #include using namespace std;int TwoPower(int n){ int w=1; for(int i=0;i!=n;i++) w=2*w; return w; } //2的n次方int main(){ int n; cin>>n; int days=0,Odays=0,s=0; bool number;
2016-08-17 20:57:47 5101
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人