Files
python/TangDou/XiTi/1163.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

82 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
//函数:r进制转换成10进制
int rToTen(string n, int r) {
//将r进制转为10进制,n是该r进制的字符串表示
int len = n.length();
int ans = 0;
int i = 0;
while (i < len) {
ans *= r;
if (n[i] >= '0' && n[i] <= '9') ans += n[i] - '0';
if (n[i] >= 'A' && n[i] <= 'Z') ans += n[i] - 'A' + 10;
if (n[i] >= 'a' && n[i] <= 'z') ans += n[i] - 'a' + 10 + 26;
i++;
}
return ans;
}
//函数:十进制转任意进制
string tenToR(int n, int r) {
if (n == 0) return "0";
//十进制n转r进制 ,返回字符串s
string str = "";
stack<int> s;
while (n) {
s.push(n % r);
n = n / r;
}
while (!s.empty()) {
switch (s.top()) {
case 10:
str += 'A';
break;
case 11:
str += 'B';
break;
case 12:
str += 'C';
break;
case 13:
str += 'D';
break;
case 14:
str += 'E';
break;
case 15:
str += 'F';
break;
default:
str += s.top() + '0';
}
s.pop();
}
return str;
}
int main() {
int n;
cin >> n;
long long min = INT32_MAX;
long long a[100] = {0};
for (int i = 0; i < n; ++i) {
string pai;
cin >> pai;
pai = pai.substr(2, pai.length() - 2);//裁掉SD
//pai按36进制转为10进制
a[i] = rToTen(pai, 36);
}
//排序,由大到小
sort(a, a + 100, less<long long>());
// 计算差值
for (int i = 99; i > 99 - n; i--) {
if (a[i] - a[i - 1] < min)min = a[i] - a[i - 1];
}
cout << min << endl;
return 0;
}