#include <stdio.h>#define N 10int main(){ int a[N-1]={3,9,4,5,2,6,1,8,10}, missing=0; for(int i=1; i<=N-1; i++){missing+=i-a[i-1]; }missing+=N; printf("Missing Number: %d\n", missing); return 0;}對於丟失一個數的情況:
#include <iostream>#include <math.h>using namespace std;void MatrixMultiplication(int * pArry1, int *pArry2, int * pDestArry, int len){int row ;int col;row= col = (int)sqrt((double)len);if (row * col != len) //矩陣不為方陣則提示矩陣無效{cout <<
#include <iostream>#include <stdio.h>#include <string.h>#include <conio.h>using namespace std;int main(){cout << "unsigned char" <<sizeof(unsigned char)<<endl;//1cout << "signed char
#include<stdio.h>#include<functional>#include<queue>#include<vector>using namespace std; struct cmp{ bool operator ()(double &a,double &b){ return a<b;} }; double a[]={12.3,34.5,9.5,2.4,6.8,7.0,33.6}; int
#include <iostream>using namespace std;void main(){unsigned char a = 0xA5;unsigned char b = ~a >> 4+1;printf("b = %d \n",b);}//250//這裡的局部變數a放在16位的寄存器中!!!!這裡需要注意的是a雖然是無符號char型,只佔一個位元組,但是它存放在一個eax寄存器,是16位的。。。於是在機器中0xA5的寄存中運算式為0000 0000 1010
#include <iostream>using namespace std;void main(){char *str = "Hello";//"hello“是儲存在字串常量儲存地區,s為其收地址,該地區是不能修改的。*str++ = 'Q';//運行崩潰cout << str <<endl;char arr[] =
#include <iostream>using namespace std;void main(){int a = 1;int b = 2;int c = 3;cout << sizeof(a) <<endl;int *pa= &a;printf("&a=%x\n",pa);int *pb = &b;printf("&b=%x\n",pb);int *pc = &c;printf("&c=%x\n",pc);}
#include <iostream>#include <vector>#include <map>#include <string>using namespace std;struct a{short aa;//2short b;//2short c;//2};//6struct b{char x;//1char y;//1char z;//1short q;//2};//6class c{private:int a;//4char
在C++的成員函數中,有一種成員函數叫做常成員函數,形如:int get() const;據百科中記載:常成員函數 含義 是通過該函數只能讀取同一類中的資料成員的值,而不能修改它。那麼要是修改了呢?那當然得到的是一個編譯錯誤。。。。那我要是非要修改呢?這時,mutable就出現了。Mutable 關鍵詞的作用是:可以在常函數中被修改其值。mutable使用的兩種情況舉例: class Employee {public: Employee(const std::string &
placement new是重載operator new的一個標準、全域的版本,它不能被自訂的版本代替(不像普通的operator new和operator delete能夠被替換成使用者自訂的版本)。它的原型如下:void *operator new( size_t, void *p ) throw() { return p; }首先我們區分下幾個容易混淆的關鍵詞:new、operator new、placement new new和delete操作符我們應該都用過,它們是對堆中的記憶體進行
#include <iostream>using namespace std;void GetMemory(char *p, int num){p = (char *)malloc(sizeof(char) * num);}void main(){char *str = NULL;GetMemory(str,100);strcpy(str,"Hello");}//編譯通過,但運行錯誤。//0x61aef689 (msvcr90d.dll) 處未處理的異常: 0xC0000005:
#include <iostream>using namespace std;void main(){ char s1[]="abc"; char s2[]="abc"; //cout << (s1==s2) <<endl;//0 //s1[1]='x';//編譯正確,輸出axc //cout << s1 <<endl; const char s3[]="abc"; const char s4[]="abc"; //cout <
使用STL中的stack#include <iostream>#include <stack>#include <assert.h>using namespace std;bool isValidSeq(char *s){assert(s != NULL);stack<char> st;char *p = s;while(*p != '\0'){if(!st.empty()){if(st.top() == '(' && *p ==
PING的實現過程很簡單,命令將引發IP層發送一個簡單的IP包,而目的方收到這個包之後,將源和目的地址做一下交換,重新發出這個包即可,當然還要加一些逾時的機制。 假定主機A的IP地址是192.168.1.1,主機B的IP地址是192.168.1.2,都在同一子網內,則當你在主機A上運行“Ping
#include <iostream>#include <stack>using namespace std;char *itoa_bxy(int num, char *a,int radix){char *tmp = a;int flag = num;//如果是負數,採用相反數來計算if(flag < 0){num = -num;}//從低位開始遍曆數字,入棧。stack<char> s;while(num != 0){char x = num %
1-32----->臉頰=========0-16一共17個點33-40---->右眼眉=======17-21一共5個點41-48---->左眼眉=======22-26一共5個點49-54---->鼻樑=========27-30一共4個點55-62---->鼻子=========31-35一共5個點63-74---->右眼=========36-41一共6個點75-86---->左眼=========42-47一共6個點87-110--->外
#include <iostream>#include <fstream>#include <vector>#include <string>#include <sstream>#define NUM_FILE 24using namespace std;void main(){vector<int> x;vector<int> y;for(int i=1; i <= NUM_FILE;
#include <iostream>using namespace std;void main(){char s1[]="abc";char s2[]="abc";cout <<boolalpha<< (s1==s2) <<endl;const char s3[]="abc";const char s4[]="abc";cout <<(s3==s4) <<endl;char *s5="abc";char *s6="
靜態路由 是在路由器中設定的固定的路由表。除非網路系統管理員幹預,否則靜態路由不會發生變化由於靜態路由不能對網路的改變作出反映,一般用於網路規模不大、拓撲結構固定的網路中。靜態路由的優點是簡單、高效、可靠。在所有的路由中,靜態路由優先順序最高。當動態路由與靜態路由發生衝突時,以靜態路由為準動態路由 是網路中的路由器之間相互連信,傳遞路由資訊,利用收到的路由資訊更新路由器表的過程。它能即時地適應網路結構的變化。如果路由更新資訊表明發生了網路變化,路由選擇軟體就會重新計算路由,並發出新的路由更新
Gabor變換由兩個檔案組成一個是gabor變換: spatialgabor.m % SPATIALGABOR - applies single oriented gabor filter to an image%% Usage:% [Eim, Oim, Aim] = spatialgabor(im, wavelength, angle, kx, ky, showfilter)%% Arguments:% im - Image to be processed.