LCP 1. 猜数字
生活随笔
收集整理的這篇文章主要介紹了
LCP 1. 猜数字
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2020-03-17
1.題目描述
猜數(shù)字2.題解
判斷對(duì)應(yīng)位置的數(shù)值是否相等即可3.代碼
#include <iostream> #include <vector> using namespace std;class Solution { public:int game(vector<int>& guess, vector<int>& answer) {int cnt=0;for (int i=0;i<3;i++){if (guess[i]==answer[i]) cnt++;}return cnt;} };int main(){Solution s;vector<int>guess = {2,2,3};vector<int>answer = {3,2,1};cout<<s.game(guess,answer)<<endl;return 0; } 新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎(jiǎng)!定制產(chǎn)品紅包拿不停!總結(jié)
以上是生活随笔為你收集整理的LCP 1. 猜数字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 27. 二叉树的镜像
- 下一篇: HashMap的hash冲突解决方案