2026年程序設(shè)計(jì)面試題目與解答示例集_第1頁(yè)
2026年程序設(shè)計(jì)面試題目與解答示例集_第2頁(yè)
2026年程序設(shè)計(jì)面試題目與解答示例集_第3頁(yè)
2026年程序設(shè)計(jì)面試題目與解答示例集_第4頁(yè)
2026年程序設(shè)計(jì)面試題目與解答示例集_第5頁(yè)
已閱讀5頁(yè),還剩14頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

2026年程序設(shè)計(jì)面試題目與解答示例集一、編程實(shí)現(xiàn)題(共3題,每題20分)1.題目(20分):背景:某電商平臺(tái)需要對(duì)用戶行為數(shù)據(jù)進(jìn)行實(shí)時(shí)統(tǒng)計(jì),要求統(tǒng)計(jì)當(dāng)前在線用戶中,活躍度最高的前K個(gè)用戶(活躍度定義為:用戶在過(guò)去1小時(shí)內(nèi)產(chǎn)生的請(qǐng)求次數(shù))。請(qǐng)?jiān)O(shè)計(jì)一個(gè)算法,支持動(dòng)態(tài)添加用戶請(qǐng)求,并實(shí)時(shí)返回前K活躍用戶。要求:-使用Python實(shí)現(xiàn),數(shù)據(jù)結(jié)構(gòu)需考慮時(shí)間復(fù)雜度和空間復(fù)雜度。-示例輸入:-添加用戶請(qǐng)求序列:`["user1","user2","user1","user3","user2","user1"]`-查詢前K活躍用戶(K=2):應(yīng)返回`["user1","user2"]`(假設(shè)時(shí)間戳隱含在添加順序中)。2.題目(20分):背景:在金融風(fēng)控場(chǎng)景中,需要檢測(cè)交易流水中的異常金額(例如,單筆金額超過(guò)閾值的5倍)。給定一個(gè)包含時(shí)間戳和金額的交易列表,要求實(shí)現(xiàn)一個(gè)函數(shù),返回所有可疑交易(金額異常或交易過(guò)于頻繁)。要求:-使用Java實(shí)現(xiàn),需考慮高并發(fā)場(chǎng)景下的線程安全。-示例輸入:javaList<Transaction>transactions=Arrays.asList(newTransaction("tx1",1000,System.currentTimeMillis()-1000),newTransaction("tx2",5000,System.currentTimeMillis()-500),newTransaction("tx3",2000,System.currentTimeMillis()-2000),newTransaction("tx1",3000,System.currentTimeMillis()));-設(shè)閾值為1000,異常條件包括:金額>5000或同一用戶2秒內(nèi)交易超過(guò)2次。3.題目(20分):背景:某物流公司需要優(yōu)化配送路線,給定多個(gè)配送點(diǎn)(坐標(biāo))和配送任務(wù)(起點(diǎn)-終點(diǎn)),要求計(jì)算最短的總配送路徑??墒褂脠D算法實(shí)現(xiàn),需考慮動(dòng)態(tài)添加任務(wù)的情況。要求:-使用C++實(shí)現(xiàn),支持動(dòng)態(tài)更新任務(wù)隊(duì)列。-示例輸入:cppvector<pair<string,pair<int,int>>>points={{"A",{0,0}},{"B",{1,2}},{"C",{3,1}}};vector<pair<string,string>>tasks={{"A","B"},{"B","C"}};-計(jì)算最短路徑(可假設(shè)距離函數(shù)為曼哈頓距離)。二、算法設(shè)計(jì)題(共2題,每題25分)1.題目(25分):背景:在社交網(wǎng)絡(luò)中,需要檢測(cè)用戶之間的潛在欺詐關(guān)系(例如,通過(guò)共同好友過(guò)多可能為虛假賬戶)。給定用戶好友關(guān)系圖,要求設(shè)計(jì)算法識(shí)別高關(guān)聯(lián)度的用戶對(duì)(例如,共同好友數(shù)超過(guò)閾值)。要求:-使用DFS/BFS實(shí)現(xiàn),需考慮圖數(shù)據(jù)結(jié)構(gòu)的存儲(chǔ)。-示例輸入:pythongraph={"user1":["user2","user3"],"user2":["user1","user4"],"user3":["user1"],"user4":["user2"]}-設(shè)閾值為2,應(yīng)識(shí)別出`("user1","user2")`和`("user2","user4")`。2.題目(25分):背景:在自然語(yǔ)言處理中,需要實(shí)現(xiàn)詞性標(biāo)注(POStagging)的動(dòng)態(tài)規(guī)劃算法。給定句子和詞典,要求標(biāo)注每個(gè)詞的詞性(如名詞、動(dòng)詞)。要求:-使用Python實(shí)現(xiàn),需考慮狀態(tài)轉(zhuǎn)移方程。-示例輸入:pythonsentence=["我","愛(ài)","編程"]vocab={"我":"PRON","愛(ài)":"VERB","編程":"NOUN"}-輸出標(biāo)注結(jié)果:`[("我","PRON"),("愛(ài)","VERB"),("編程","NOUN")]`。三、系統(tǒng)設(shè)計(jì)題(共1題,30分)1.題目(30分):背景:設(shè)計(jì)一個(gè)高并發(fā)的短鏈接系統(tǒng)(如tinyURL),需支持URL生成、解析和分布式緩存。要求:-描述系統(tǒng)架構(gòu)(數(shù)據(jù)庫(kù)、緩存、負(fù)載均衡)。-實(shí)現(xiàn)核心的URL編碼/解碼算法(可使用Base62)。-示例輸入:javagenerate("");//輸出"a1b2"parse("a1b2");//返回""答案與解析一、編程實(shí)現(xiàn)題1.答案(Python):pythonimportheapqclassTopKActiveUsers:def__init__(self,k):self.k=kself.user_counts={}self.heap=[]defadd_request(self,user):ifuserinself.user_counts:self.user_counts[user]+=1else:self.user_counts[user]=1iflen(self.heap)<self.k:heapq.heappush(self.heap,(-self.user_counts[user],user))elifself.user_counts[user]>-self.heap[0][0]:heapq.heapreplace(self.heap,(-self.user_counts[user],user))defget_top_k(self):return[userfor_,userinsorted(self.heap,reverse=True)]示例tk=TopKActiveUsers(2)requests=["user1","user2","user1","user3","user2","user1"]forreqinrequests:tk.add_request(req)print(tk.get_top_k())#輸出["user1","user2"]解析:-使用字典`user_counts`記錄用戶請(qǐng)求次數(shù),堆`heap`維護(hù)前K大用戶。-時(shí)間復(fù)雜度:`O(logk)`(每次添加操作),空間復(fù)雜度:`O(k)`。2.答案(Java):javaimportjava.util.;classTransaction{Stringid;intamount;longtimestamp;publicTransaction(Stringid,intamount,longtimestamp){this.id=id;this.amount=amount;this.timestamp=timestamp;}}publicclassFraudDetection{privatestaticfinalintTHRESHOLD=5000;privateMap<String,Transaction>recentTransactions=newConcurrentHashMap<>();privateMap<String,Integer>userFrequency=newConcurrentHashMap<>();publicvoidaddTransaction(Transactiontx){if(tx.amount>THRESHOLD){System.out.println("Suspicious:"+tx);}longcurrentTime=System.currentTimeMillis();recentTransactions.values().removeIf(t->currentTime-t.timestamp>2000);recentTransactions.put(tx.id,tx);userFrequency.put(tx.id,userFrequency.getOrDefault(tx.id,0)+1);if(userFrequency.get(tx.id)>2){System.out.println("Suspicious:"+tx);}}publicstaticvoidmain(String[]args){FraudDetectionfd=newFraudDetection();List<Transaction>txs=Arrays.asList(newTransaction("tx1",1000,System.currentTimeMillis()-1000),newTransaction("tx2",5000,System.currentTimeMillis()-500),newTransaction("tx3",2000,System.currentTimeMillis()-2000),newTransaction("tx1",3000,System.currentTimeMillis()));for(Transactiontx:txs){fd.addTransaction(tx);}}}解析:-使用`ConcurrentHashMap`確保線程安全。-檢測(cè)條件:金額異?;蛴脩纛l率過(guò)高。3.答案(C++):cppinclude<vector>include<string>include<unordered_map>include<queue>include<algorithm>usingnamespacestd;structPoint{stringid;intx,y;};structEdge{intfrom,to;intdist;};intmanhattan(pair<int,int>a,pair<int,int>b){returnabs(a.first-b.first)+abs(a.second-b.second);}vector<int>dijkstra(constvector<vector<Edge>>&graph,intstart,intn){vector<int>dist(n,INT_MAX);priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;dist[start]=0;pq.push({0,start});while(!pq.empty()){intd=pq.top().first;intu=pq.top().second;pq.pop();if(d>dist[u])continue;for(auto&e:graph[u]){intv=e.to;intalt=d+e.dist;if(alt<dist[v]){dist[v]=alt;pq.push({alt,v});}}}returndist;}intmain(){vector<Point>points={{"A",{0,0}},{"B",{1,2}},{"C",{3,1}}};vector<vector<Edge>>graph(3,vector<Edge>());graph[0].push_back({0,1,manhattan({0,0},{1,2})});graph[1].push_back({1,0,manhattan({1,2},{0,0})});graph[1].push_back({1,2,manhattan({1,2},{3,1})});graph[2].push_back({2,1,manhattan({3,1},{1,2})});vector<int>dist=dijkstra(graph,0,3);for(intd:dist)cout<<d<<"";return0;}解析:-使用Dijkstra算法計(jì)算最短路徑,動(dòng)態(tài)更新任務(wù)隊(duì)列可通過(guò)維護(hù)優(yōu)先隊(duì)列實(shí)現(xiàn)。二、算法設(shè)計(jì)題1.答案(Python):pythondeffind_highly_connected_pairs(graph,threshold):common_friends={}foruser,friendsingraph.items():forfriendinfriends:iffriendnotingraph:continueshared=set(friends).intersection(graph[friend])iflen(shared)>=threshold:if(user,friend)notincommon_friends:common_friends[(user,friend)]=len(shared)elif(friend,user)notincommon_friends:common_friends[(friend,user)]=len(shared)return[pairforpair,countincommon_friends.items()ifcount>=threshold]示例graph={"user1":["user2","user3"],"user2":["user1","user4"],"user3":["user1"],"user4":["user2"]}print(find_highly_connected_pairs(graph,2))#輸出[("user1","user2"),("user2","user4")]解析:-遍歷圖,統(tǒng)計(jì)每對(duì)用戶的共同好友數(shù)量,超過(guò)閾值則記錄。2.答案(Python):pythondefpos_tagging(sentence,vocab):n=len(sentence)dp=[[""]nfor_inrange(2)]foriinrange(n):word=sentence[i]ifwordinvocab:forjinrange(i+1):ifj==0:dp[i%2][j]=(word,vocab[word])else:dp[i%2][j]=max(dp[(i-1)%2][j-1],dp[(i-1)%2][j],key=lambdax:x[1]ifx[1]else-1)[0]dp[i%2][i]=(word,vocab[word])returndp[(n-1)%2]示例sentence=["我","愛(ài)","編程"]vocab={"我":"PRON","愛(ài)":"VERB","編程":"NOUN"}print(pos_tagging(sentence,vocab))#輸出[("我","PRON"),("愛(ài)","VERB"),("編程","NOUN")]解析:-動(dòng)態(tài)規(guī)劃,狀態(tài)轉(zhuǎn)移基于前一個(gè)詞的詞性。三、系統(tǒng)設(shè)計(jì)題答案(Java):javaimportjava.util.;publicclassShortLinkSystem{privatestaticfinalStringBASE62="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";privateMap<String,String>urlMap=newConcurrentHashMap<>();privateMap<String,String>reverseMap=newConcurrentHashMap<>();privateintcount=0;publicString

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論