Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

输出机器的CPU型号(适用于OJ)

用CPUID检测OJ测评机所用的CPU

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdint.h>
#include <iostream>
#include <cpuid.h>
static void cpuid(uint32_t func, uint32_t sub, uint32_t data[4])
{
__cpuid_count(func, sub, data[0], data[1], data[2], data[3]);
}
int main()
{
uint32_t data[4];
char str[48];
for (int i = 0; i < 3; ++i)
{
cpuid(0x80000002 + i, 0, data);
for (int j = 0; j < 4; ++j)
reinterpret_cast<uint32_t *>(str)[i * 4 + j] = data[j];
}
std::cout << str;
}
  • 洛谷:Intel(R) Xeon(R) Platinum 8369HC CPU @ 3.30GHz
  • Acwing:Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz

参考:https://zhuanlan.zhihu.com/p/28322626