MENU

小米OJ板qi刷keng记录

小米OJ

刷题获得OJ币,OJ币兑换奖品,发财!

#1 A+B

标程居然坑数据范围QAQ(啥也不看直接抄的下场

这系统也太不稳定力,提交记录一大半系统错误,,,

#include<iostream>
#include<cstdint>
int64_t a, b;
int main() {
    std::cin >> a >> b;
    std::cout << a + b;
}

#2 找出单独出现的数字

#include<iostream>
#include<cstdint>
#include<vector>
#include<iterator>
#include<algorithm>
std::vector<int32_t> v{ std::istream_iterator<int32_t>(std::cin), std::istream_iterator<int>() };
int main() {
    std::sort(v.begin(), v.end());
    for (auto i = v.begin(); i < v.end() - 1; i += 2)if (*i != *(i + 1))return (std::cout << *i), 0;
    std::cout << *v.rbegin();
}

#3 大数相减

不让我用我偏要用,哼!

def solution(line):
    for i in range(len(line)):
        if(line[i] == '-'):
            n = i
            break
    return int(line[:n]) - int(line[n+1:])

#4 最长连续数列

读入有毒.jpg

给个数据范围呀鸽鸽

题目说的要 $O(n)$是假的(

#include<iostream>
#include<cstdint>
#include<cstring>
#include<cctype>
#include<algorithm>
char buf[1234567];
int32_t len, n, a[1000000], ans = 1, cur = 1;
int main() {
    std::cin >> buf, len = strlen(buf);
    int32_t i = 0;
    while (i < len) {
        while (i < len && !isdigit(buf[i]))++i;
        if (i == len)break;
        while (isdigit(buf[i]))a[n] = a[n] * 10 + buf[i++] - '0';
        ++n;
    }
    std::sort(a, a + n);
    for (int i = 1; i <= n; ++i) {
        if (a[i] == a[i - 1] + 1)++cur;
        else {
            if (ans < cur)ans = cur;
            cur = 1;
        }
    }
    std::cout << ans;
}

#5 找出旋转有序数列的中间值

和旋转有个**关系???

#include<iostream>
#include<cstdint>
#include<cstring>
#include<cctype>
#include<algorithm>
char buf[1234567];
int32_t len, n, a[1000000], ans = 1, cur = 1;
int main() {
    std::cin >> buf, len = strlen(buf);
    int32_t i = 0;
    while (i < len) {
        while (i < len && !isdigit(buf[i]))++i;
        if (i == len)break;
        while (isdigit(buf[i]))a[n] = a[n] * 10 + buf[i++] - '0';
        ++n;
    }
    std::nth_element(a, a + (n >> 1), a + n), std::cout << a[n >> 1];
}

#6 交叉队列

什么辣鸡读入方式,太难受了,不做了,,,

草(双语)

Leave a Comment

captcha
请输入验证码