編程之美-尋找發帖水王

來源:互聯網
上載者:User
Type Find(Type *ID,int N){//尋找發帖"水王",假設只有一個Type candidate;int nTimes,i;for( i = nTimes = 0; i < N; i++){if(nTimes == 0){candidate = ID[i];nTimes = 1;}else{if(candidate == ID[i])nTimes++;elsenTimes--;}}return candidate;}void Findall(Type *ID,Type *id1,Type *id2,Type *id3,int N){//尋找發帖"水王",假設有多個Type candidate1,candidate2,candidate3;int nTime1,nTime2,nTime3,i;Type noexitID = 127;nTime1 = nTime2 = nTime3 =0;candidate1 = candidate2 = candidate3 = noexitID;for(i = 0 ; i < N; ++i){if(candidate1 == ID[i]){nTime1++;}else if(candidate2 == ID[i]){nTime2++;}else if(candidate3 == ID[i]){nTime3++;}else if(nTime1 == 0 ){candidate1 = ID[i];nTime1 = 1;}else if(nTime2 == 0 ){candidate2 = ID[i];nTime2 = 1;}else if(nTime3 == 0){candidate3 = ID[i];nTime3 = 1;}else {nTime1--;nTime2--;nTime3--;}}*id1 = candidate1;*id2 = candidate2;*id3 = candidate3;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.