#include <iostream>#include <string>using namespace std;string Left[3], Right[3], result[3];bool dealLight(char& ch){for(int i = 0; i < 3; ++i){switch(result[i][0]){//u -> up,d -> down,e -> evencase
#include <iostream>#include <fstream>using namespace std;#define MAX 46int Fibonacci[MAX];int main(){int N, n;int cnt = 0;Fibonacci[1] = 2;Fibonacci[2] = 3;for(int i = 3; i <= 45; ++i)Fibonacci[i] = Fibonacci[i-1] +
寫一個鏈表的的操作的例子,雖然沒什麼難度,但是好久沒寫了,練練手。 #include<stdio.h>typedef struct tagLinkNode //定義一個節點結構體...{ char m_type; struct tagLinkNode *next;}LinkNode;LinkNode* CreatLinkList(int n) //建立鏈表的函數...{
林銳的《高品質C/C++程式設計指南》有這樣一個例子:void GetMemory(char *p, int num){ p = (char*)malloc(sizeof(char)*num);}int main(){ char *str = NULL; GetMemory(str, 100); strcpy(str, "hello"); }書中也說這樣用是完全錯誤的,但是錯誤的原因書中解釋的並不是很容易讓人理解為了便於大家理解我們可以用gcc這個工具來查看彙編代碼以下是GetMemory函數:
我們繼續討論關於指標傳遞記憶體的問題《高品質C/C++程式設計指南》中這樣用是正確void GetMemory2(char **p, int num){ *p = (char*)malloc(sizeof(char)*num);}int main(){ char *str =NULL; GetMemory2(&str, 100); strcpy(str,
#include <iostream>using namespace std;#define MAX 1005int map[MAX];int result[MAX];struct Stack{int stack[MAX];int index;Stack():index(0){}void push(int& v){stack[index++] = v;}int pop(){return stack[--index];}int top(){return stack[index-
讓我們繼續前兩次的討論我們同樣可以使用把指標作為傳回值的方法來傳遞記憶體,而且我個人認為這是值得推薦的方式c代碼:char *GetMemory3(int num){ char *p = (char *)malloc(sizeof(char)*num); return p;}int main(){ char *str = NULL; str = GetMemory3(100); strcpy(str, "hello"); printf("%s",
#include <iostream>using namespace std;int map[9][9] = {{1,1,0,1,1,0,0,0,0},{1,1,1,0,0,0,0,0,0},{0,1,1,0,1,1,0,0,0},{1,0,0,1,0,0,1,0,0},{0,1,0,1,1,1,0,1,0},{0,0,1,0,0,1,0,0,1},{0,0,0,1,1,0,1,1,0},{0,0,0,0,0,0,1,1,1},{0,0,0,0,1,1,0,1,1}};int v[9
最近看到很多人在詢問交換器、集線器、路由器是什麼,功能如何,有何區別,筆者就這些問題簡單的做些解答。首先說HUB,也就是 集線器 。它的作用可以簡單的理解為將一些機器串連起來組成一個區域網路。而 交換器 (又名交換式集線器)作用與集線器大體相同。但是兩者在效能上有區別:集線器採用的式共用頻寬的工作方式,而交換器是獨享頻寬。這樣在機器很多或資料量很大時,兩者將會有比較明顯的。而 路由器 與以上兩者有明顯區別,它的作用在於串連不同的網段並且找到網路中資料轉送最合適的路徑
#include <iostream>using namespace std;int n1, n2;bool map[10000];int value[10000];int q[11000];int c[4]= {1, 10, 100, 1000};bool bfs(){int front = 0, rear = 0;q[rear++] = n1;value[n1] = 0;while(front < rear){int temp = q[front++];if(temp ==
#include <iostream>#include <cmath>using namespace std;int hash[46];int main(){int n;scanf("%d", &n);__int64 sum;for(__int64 i = 0; i < (__int64)pow(10.0, n/2); ++i){sum = 0;__int64 p = 1;for(int j = 0; j < n/2; ++j){sum +=
#include <iostream>using namespace std;int main(){int n, x;while(scanf("%d", &n) && n){x = n&-n; // 後面0的個數m的2^mprintf("%d/n", n+x + (n^(n+x))/x/4);// n+x 將從右往左第一個01變成10// (n^(n+x))/x/4 將剩下(除了變化的那兩位,故除4)的1移位}return 0;}
#include <iostream>#include <climits>using namespace std;#define MAXF 101#define MAXV 101int A[MAXF][MAXV];int f[MAXF][MAXV];int main(){int F, V;scanf("%d%d", &F, &V);for(int i = 1; i <= F; ++i)for(int j = 1; j <= V;
#include <iostream>using namespace std;int main(){int n;scanf("%d", &n);int i, sum = 0;bool OverFlag = false;for(i = 1;; i++){sum += i;if(sum == n){printf("%d/n", i);OverFlag = true;break;}else if(sum > n)break;}if(!OverFlag){while((sum
#include <iostream>using namespace std;#define MAX 1001int A[MAX];int L[MAX];int main(){int n, max;scanf("%d", &n);for(int i = 1; i <= n; ++i)scanf("%d", &A[i]);//dpL[1] = 1;for(int i = 1; i <= n-1; ++i){max = 1;for(int j = 1; j &
//AC Code#include <iostream>#define Swap(x,y) {int temp = x;x = y;y = temp;}#define MAX 50001int map[MAX];bool hash[MAX];int main(){int i, j, k, n, v;while(scanf("%d%d", &n, &v) && n != -1){memset(hash, false, sizeof(bool)*(n+1)
#include <iostream>using namespace std;int f(int m, int n){if(m < 0)return 0;if(m == 0 || n == 1)return 1;return f(m, n-1) + f(m-n, n);}int main(){int n;scanf("%d", &n);int M, N;while(n--){scanf("%d%d", &M, &N);printf("%d/n",
隨便寫的一個字串的操作可以在一個子串中求出某一個子串的出現次數和出現的位置。 #include<iostream>#include<string>using namespace std;int PartPostion(char src[], char partString[], int pos)
#include <iostream>using namespace std;int map[7][8];//5*6int result[7][8];int main(){int N;int cnt = 0;scanf("%d", &N);while(N--){memset(result, 0, 7*8*sizeof(int));for(int i = 1; i <= 5; ++i)for(int j = 1; j<= 6; ++j)scanf("%d",
今天看見一個人發帖說什麼他看見報道說盧旺達話務中心的大學生每月正1000美金。他還憤憤不平的說在中國工資如何如何少,發泄心中的不滿情緒。 後來有一個網友回帖說他去過盧旺達,實事並非如此,本科生畢業工資能超過100美金就不錯,只有很少的管理員才能達到400美金。