Time of Update: 2018-12-03
1、布爾變數的比較:if (flag)if (!flag)用邏輯非!運算子,因為它適合布爾變數。 2、整型變數的比較:if (value == 0) if (value != 0)就用普通的==和!=運算子。 3、浮點型變數的比較:if (x == 0.0) // 錯誤的可能極大if ((x>=-EPSINON) &&
Time of Update: 2018-12-03
strcat:// strcat#include <stdio.h>#include <string.h>char *Strcat(char *dest, const char *src){char *tmp = dest;while ('\0' != *dest) {dest++;}while ('\0' != (*dest++ = *src++)) {;}return tmp;}int main(int argc, char **argv){char string[1
Time of Update: 2018-12-03
http://acm.nyist.net/JudgeOnline/problem.php?pid=2 1、My Code: #include <iostream>#include <cstring>using namespace std;#define MAXSIZE 10005int main(void){int k;cin >> k;while(k--){char str[MAXSIZE];cin >> str;char
Time of Update: 2018-12-03
先上一段代碼:#include <iostream>using namespace std;int main(void){int a = 1;const int *p = NULL;p = &a;int *q = p;//錯誤//error C2440: 'initializing' : cannot convert from 'const int *' to 'int *'//Conversion loses qualifiersq = &a;//(1)q =
Time of Update: 2018-12-03
strchr:// strchr#include <stdio.h>char *Strchr(const char *s, int c){for (; *s != (char)c; ++s) {if (*s == '\0') {return NULL;}}return (char *)s;}int main( int argc, char **argv ){char string[] = "The quick brown dog jumps over the lazy
Time of Update: 2018-12-03
挺搞笑的,前幾天運動會,我們必須作為托去看台看比賽。我就第一天看了開幕式,後來的三天都沒去了,所以後果很嚴重,受到了警告的處分,其實沒去看運動會的時候我都去圖書館上自習了=_=,看到圖書館不也有很多人嗎?當然了,處分的後果是一系列的,“錢”、入黨、評優各種都沒了,其實我也做好了這最壞的打算!錢這方面,我是無所謂的,但是我覺得對不起父母,苦了我勞作的父母親。入黨,必須延遲一年。評優,我也淡然了。更悲催的是,還有位成績不錯的基友受到“嚴重警告”,亮了。自嘲完畢。
Time of Update: 2018-12-03
看了bitset的源碼,發現要重載下標運算子[]內容還挺多的,作右值時相對簡單,只用來測試。作左值時就比較麻煩,因為要修改它的值。 1、作右值舉個例子:const bitset<10> b;bool tag;tag = b.test(2);tag = b[2];上面第三句和第四句效果一樣,都是測試b的下標為2的位是否為1。當bitset為const時,operator[]執行的是:bool operator[](size_t _Pos) const{// subscript
Time of Update: 2018-12-03
http://poj.org/problem?id=11631、普通遞迴#include <iostream>#include <cstring>#include <cstdio>using namespace std;#define __max(a,b) (((a) > (b)) ? (a) : (b))#define MAXNUM 101int N;int aMax[MAXNUM][MAXNUM];//aMax is memorandumint
Time of Update: 2018-12-03
(起征點800):#include <iostream>using namespace std;#define TAX_THRESHOLD 800struct Tax {double standard;double tax_rate;};class Salary {double income;public:static Tax tax_array[];Salary(int m = 0) {income = m;}void operator - (int payout)
Time of Update: 2018-12-03
程式:// 定點小數補碼一位乘(校正法)// http://blog.csdn.net/justme0#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <bitset>#include <string>using namespace std;const int n = 4;// 數值位位元// a,b聯合右移(算術移位)void RightMove(bitset<n + 2>
Time of Update: 2018-12-03
單調遞增最長子序列 描述求一個字串的最長遞增子序列的長度如:dabdbf最長遞增子序列就是abdf,長度為4輸入第一行一個整數0<n<20,表示有n個字串要處理隨後的n行,每行有一個字串,該字串的長度不會超過10000輸出輸出字串的最長遞增子序列的長度範例輸入3aaaababcabklmncdefg範例輸出137 Accepted #include<stdio.h>int length(char * s){int len[128] = {0}, i, t;for(;
Time of Update: 2018-12-03
《C++標準程式庫》上關於優先隊列的介紹:#include <iostream>#include <queue>using namespace std;int main(void){priority_queue<double> q;q.push(66.6);q.push(22.2);q.push(44.4);cout << q.top() << ' ';q.pop();cout << q.top() <<
Time of Update: 2018-12-03
1、可能有的人涉及到動態分配只用到下面的這句:#include <iostream>using namespace std;int main(void){int *p;p = new int(1);//1cout << *p << endl;int *q;q = (int *)malloc(sizeof(int));*q = 1;cout << *q << endl;return
Time of Update: 2018-12-03
程式:// 定點小數補碼一位乘(Booth比較法)// http://blog.csdn.net/justme0#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <bitset>#include <string>using namespace std;const int n = 4;// 數值位位元// a,b聯合右移(算術移位)void RightMove(bitset<n +
Time of Update: 2018-12-03
http://acm.pku.edu.cn/JudgeOnline/problem?id=1088 先MARK,待自己慢慢研究出來再A! http://www.cppblog.com/AClayton/archive/2007/09/17/32336.aspx #include <iostream>#include <cstdio>#include <cstdlib>using namespace std;#define MAXNUM 10int
Time of Update: 2018-12-03
定義一個任意進位的數Number類,繼承自string類:Number類的資料成員:_radix表示數的基數,_inum表示數的相應的十進位數用string儲存任意進位的數(可以說是用字串來存,r進位的數不適合用int來存)/*Number類的資料成員:_radix表示數的基數,_inum表示數的相應的十進位數*/// more: http://msdn.microsoft.com/en-us/library/0heszx3w.aspx#include
Time of Update: 2018-12-03
直接插入排序時間複雜度O(n^2)附加空間O(1)穩定排序#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;#define LEN 8//有LEN個元素要排struct Record {//為了考察排序的穩定性,定義元素是結構體類型int key;int otherinfo;};void InsertSort(Record *arr, int length)//length是要排序的元素的個數,
Time of Update: 2018-12-03
strstr:// strstr#include <stdio.h>char *Strstr(const char *strLong, const char *strShort){char *cp = (char *)strLong;// cp是當前strShort的頭在strLong中的位置char *pL = NULL;char *pS = NULL;if ('\0' == *strShort)return (char *)strLong;while ('\0' != *cp){
Time of Update: 2018-12-03
折半插入排序時間複雜度O(n^2)附加空間O(1)穩定排序#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;#define LEN 8//有LEN個元素要排struct Record {//為了考察排序的穩定性,定義元素是結構體類型int key;int otherinfo;};void BInsertSort(Record *arr, int
Time of Update: 2018-12-03
表插入時間複雜度O(n^2)附加空間O(1)穩定排序#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;#define LEN 8//有LEN個元素要排struct Record {//為了考察排序的穩定性,定義元素是結構體類型int key;int otherinfo;int next;};void LinkListInsertSort(Record *arr, int