题解 | 小红的三带一

小红的三带一

https://www.nowcoder.com/practice/f71aec371e30425dbe3cc509bafe4158

#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
   int n;
   cin>>n;
   if(n>4){
     int left=0;
   int right=3;
    vector<int>s;
    int temp;
    while(cin>>temp){
        s.push_back(temp);
    }
    int count=0;
    while(right<n){
        map<int,int>k;
        for(int i=left;i<=right;i++){
            k[s[i]]++;
            //cout<<s[i]<<" ";
        }
        //cout<<endl;
        for(auto it:k){
            if(it.second==3){
                left+=3;
                right+=3;
                count++;
            }
        }
        left++;
        right++;
    }
    cout<<count;
   }
   
  
   
}
// 64 位输出请用 printf("%lld")

左右指针的基本操作

全部评论

相关推荐

01-15 13:45
门头沟学院 Java
牛客92772631...:boss招聘挂岗位是要花钱的,花了钱不挂白不挂,别那么焦虑,但是也要做好跳槽的准备
找实习记录
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务