Time of Update: 2018-12-06
//不開闢用於交換資料的臨時空間,如何完成字串的逆序(在技術一輪面試中,有些面試官會這樣問)#include "stdafx.h"void change(char *str) { for(int i=0,j=strlen(str)-1; i<j; i++, j--){ str[i] ^= str[j] ^= str[i] ^= str[j];//等價於 str[i] ^= str[j]; str[j] ^= str[i];str[i] ^=
Time of Update: 2018-12-06
輸入1則輸出0,輸入0則輸出1那天小面試了吧,遇到這麼個問題:輸入0則輸出1,輸入1則輸出0,當時想出前三種,最近在思考到底有沒有其他方法來解答。1.最常見的IF-ELSE解法,最先進入腦海,當然,還有點傻傻的問HR,if-else判斷算一種嗎? 1: #include <iostream> 2: 3: using namespace std; 4: int main() 5: { 6: int input; 7: cin >> input; 8
Time of Update: 2018-12-06
在分析某個C++源檔案的過程中,有這樣一行變數定義式: int t_from=20,t_to=12,t_length=120,i_count,t_usetime;
Time of Update: 2018-12-06
題目:找出一個二維數組中的鞍點,即該位置上的元素在該行上最大,在該列上最小。也可能沒有鞍點。#include<iostream>using namespace std;void find_andian(int n,int m,int (*a)[4]){// int *p=a[0]; int fl=0; int fh=0; int con=0; for(int i=0;i<n;i++) { int max=a[i][0]; int min=a[i][0]; for(
Time of Update: 2018-12-06
一、R檔案失蹤案1. 背景:前些時候,在進行Android程式開發過程中協助同學修改xml代碼時候,偶爾會出現R類檔案離奇失蹤事件,當時經過一些恢複操作無果後,只好重建一個工程。由於R類檔案在Android工程中是一個極其特殊的存在,所以我就此進行了一些小測試。2. 失蹤者資料:R類檔案是由ADT自動產生的一個檔案,居所是gen目錄下,其會為每一個資源定義唯一的ID,而整個工程就是通過ID的識別來引用相關資源,故R類檔案可謂是我們工作的資源中心。 3. 案情分析:由於R類檔案的特殊性,故其的作用
Time of Update: 2018-12-06
unsigned int intvert(unsigned int x,int p,int n)實現對 x 的進行轉換,p 為起始轉化位,n 為需要轉換的長度,假設起始點在右邊.如 x= 0b0001 0001,p=4,n=3 轉換後 x=0b0110 0001 #include<iostream>#include<assert.h>using namespace std;unsigned int intvert(unsigned int
Time of Update: 2018-12-06
求符合指定規則的數給定函數d(n) = n + n的各位之和,n為正整數,如 d(78) = 78+7+8=93。 這樣這個函數可以看成一個產生器,如93可以看成由78產生。 定義數A:數A找不到一個數B可以由d(B)=A,即A不能由其他數產生。現在要寫程式,找出1至10000裡的所有符合數A定義的數。 輸出: 1 3 … #include<iostream>using namespace std;int d(int i){ int j=i; int sum=0; while(i!=
Time of Update: 2018-12-06
假設一整型數組存在若干正數和負數,現在通過某種演算法使得該數組的所有負數在正數的左邊,且保證負數之間和正數之間元素相對位置不變。時空複雜度要求分別為:o(n),o(1)例如 -3 4 2 -1 7 3 -5 排序後 -3 -1 -5 4 2 7 3我的想法:#include<iostream>using namespace std;void arraydivsort(int a[],int n){ int temp=0; int k=0; int
Time of Update: 2018-12-06
什麼是二進位檔案 什麼是ASCII 什麼是文字檔 它們之間有什麼區別ASCII檔案也稱為文字檔,這種檔案在磁碟中存放時每個字元對應一個位元組,用於存放對應的ASCII碼。例如,數5678的儲存形式為:5 6 7 8 二進位檔案是按二進位的編碼方式來存放檔案的。 例如, 數5678的儲存形式為: 00010110 00101110隻佔二個位元組。二進位檔案雖然也可在螢幕上顯示,
Time of Update: 2018-12-06
1 好處 及 用途 紅/黑樹狀結構並不追求“完全平衡”——它只要求部分地達到平衡要求,降低了對旋轉的要求,從而提高了效能。紅/黑樹狀結構能夠以O(log2 n) 的時間複雜度進行搜尋、插入、刪除操作。此外,由於它的設計,任何不平衡都會在三次旋轉之內解決。當然,還有一些更好的,但實現起來更複雜的資料結構
Time of Update: 2018-12-06
深入理解按位異或運算子參與運算的兩個值,如果兩個相應bit位相同,則結果為0,否則為1。即: 0^0 = 0, 1^0 = 1, 0^1 = 1, 1^1 = 0按位異或的3個特點:(1) 0^0=0,0^1=1 0異或任何數=任何數(2) 1^0=1,1^1=0 1異或任何數-任何數取反(3) 任何數異或自己=把自己置0按位異或的幾個常見用途:(1) 使某些特定的位翻轉 例如對數10100001的第2位和第3位翻轉,則可以將該數與000001
Time of Update: 2018-12-06
#include<iostream>using namespace std;pair<int,int> mypair;int count_1(int n) //統計一個數值中含有“1”的個數{ int sum=0; while(n!=0) { if(n%10==1) { sum++; } n/=10; } return sum;}int f(int n) //<=n內的所有數值含有“1”的個數的總和{ int sum=0; while(n) {
Time of Update: 2018-12-06
原廠模式, Factory 方法模式,單例模式, 外觀(Facade)模式, 觀察者(Observer)模式,橋接(Bridge)模式都是比較常用的,不同的項目有不同的設計方向,可以參考的設計模式也不盡相同,沒有定數,只是上面這幾個模式用的比較多一些。 其他的模式我找了一下,都列出來了。
Time of Update: 2018-12-06
vector向量中的插入值如所示:#include <iostream>#include <vector>#include<string>using namespace std;pair<int ,string> fun(const string &str){vector<string> substrs;int maxcount=1,count=1;string substr;int
Time of Update: 2018-12-06
運用歸併排序的思想,實現這個求交集!#include<iostream>using namespace std;void merge(int a[],int b[],int n,int m){ int i=0,j=0; while(i<n&&j<m) { if(a[i]==b[j]) { cout<<"兩個數組中重複的數字其中一個是:"<<a[i]<<endl; i++; j++; } else
Time of Update: 2018-12-06
跟一個朋友談堆棧的時候 就寫下了這段文字,順便發到這裡給需要的看看吧彙編初學者比較頭痛的一個問題////////////////////////////////////////////////////////////////////比如 我們有這樣一個C函數 1#include<stdio.h> 2long test(int a,int b) 3{ 4 a = a + 1; 5 b = b + 100; 6 return a + b; 7} 8void main()
Time of Update: 2018-12-06
SCTP 學習小程式[borrow from internet] ubuntu 下安裝 libsctp, lksctp(不行的話在redHat下實驗)apt-get install libsctp lksctp服務端程式 1: #include <stdio.h> 2: #include <stdlib.h> 3: #include <string.h> 4: #include <sys/types.h> 5: #include
Time of Update: 2018-12-06
#include<iostream>using namespace std;typedef struct student{ int data; struct student *next;}node;void JOSEPHUS(int k,int m) //建立單鏈表{ node *head,*p,*s; int x,cycle=1; head=(node
Time of Update: 2018-12-06
遊戲:天龍八部版本:0.13.0402系統:windows xp工具:CE5.2+OD1.10目標:搜尋人物基地址第一步,用CE搜尋人物HP,得到一堆地址,掉血後繼續搜尋,得到唯一地址0ABDC360(HP地址)第二步,切換地圖後發現該地址裡的值已經不是HP,是動態地址,重複第一步搜尋出新的HP地址(地址省略)第三步,這時候不再切換地圖,用CE5.2對找到的HP地址下寫訪問記憶體斷點,此步也可用OD下寫記憶體斷點,找到彙編語句如下0044B280 55 PUSH
Time of Update: 2018-12-06
數組 a[N],存放了 1 至 N-1 個數,其中某個數重複一次。寫一個函數,找出被重複的數字 .時間複雜度必須為 o(N)函數原型:方法一:#include<iostream>using namespace std;int main(){ int a[]={1,2,3,4,5,6,8,7,8}; int n=sizeof(a)/sizeof(int); int j=n-1; for(int i=0;i<n&&j>i;) { if(a[i]!=a[j]