题解 | 小红的三带一

小红的三带一

https://www.nowcoder.com/practice/f71aec371e30425dbe3cc509bafe4158?channelPut=tracker3

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    int ans = 0;
    for (int i = 0; i + 3 < n; ) {
        int x1 = a[i], x2 = a[i+1], x3 = a[i+2], x4 = a[i+3];
        
        vector<int> tmp = {x1, x2, x3, x4};
        sort(tmp.begin(), tmp.end());
  
        if ((tmp[0] == tmp[2] && tmp[3] != tmp[0]) || 
            (tmp[1] == tmp[3] && tmp[0] != tmp[1])) {
            ans++;
            i += 4;  
        } else {
            i++;  
        }
    }
    
    cout << ans << endl;
    return 0;
}

全部评论

相关推荐

03-06 20:09
贵州大学 Java
King987:你这个学历找个中大厂刷实习经历都是可以的,但是项目要有亮点才行,这个什么外卖就不要做了,去找找最新的项目,至少涉及高并发或者是新型的AI技术mcp rag啥的 ,我在出简历点评,但是你这个没什么好点评的,内容太少,而且含金量太低。自己改一改吧,或者看一下我的项目地址中,那里有大厂最近做过的实习项目
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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