https://codeforces.com/gym/102082
题意:按照它的规则来判断字符串的大小。
分析:按照题意模拟即可。
#include "bits/stdc++.h"
namespace fastIO {
#define BUF_SIZE 100000
bool IOerror = 0;
inline char nc() {
static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
if (p1 == pend) {
p1 = buf;
pend = buf + fread(buf, 1, BUF_SIZE, stdin);
if (pend == p1) {
IOerror = 1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; }
inline void read(long long &x) {
char ch;
while (blank(ch = nc()));
if (IOerror) return;
for (x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
}
#undef BUF_SIZE
};
using namespace fastIO;
using namespace std;
const int mod = 1e9 + 7;
int cmp(string s, string t) {
if ((s[0] >= '0' && s[0] <= '9') && ((t[0] >= '0' && t[0] <= '9'))) {
int pos1 = s.length() - 1, pos2 = t.length() - 1;
if (pos1 < pos2)return -1;
else if (pos1 > pos2)return 1;
else {
pos1 = pos2 = 0;
while (pos1 < s.length()) {
if (s[pos1] < t[pos2])return -1;
else if (s[pos1] > t[pos2])return 1;
pos1++;
pos2++;
}
return 0;
}
} else if ((s[0] >= '0' && s[0] <= '9') && ((t[0] < '0' || t[0] > '9'))) {
return -1;
} else if ((s[0] < '0' || s[0] > '9') && ((t[0] >= '0' && t[0] <= '9'))) {
return 1;
} else {
return s.compare(t);
}
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
while (n--) {
string t;
cin >> t;
int pos1 = 0, pos2 = 0;
int ans;
while (1) {
string s1 = "", s2 = "";
if (pos1 == s.length() && pos2 == t.length()) {
ans = 0;
break;
} else if (pos1 == s.length() && pos2 < t.length()) {
ans = -1;
break;
} else if (pos1 < s.length() && pos2 == t.length()) {
ans = 1;
break;
}
while (pos1 < s.length() && (s[pos1] >= '0' && s[pos1] <= '9'))s1 += s[pos1++];
while (pos2 < t.length() && (t[pos2] >= '0' && t[pos2] <= '9'))s2 += t[pos2++];
if (s1 == "")s1 += s[pos1++];
if (s2 == "")s2 += t[pos2++];
int x = cmp(s1, s2);
if (x == 0)continue;
else if (x == 1) {
ans = 1;
break;
} else if (x == -1) {
ans = -1;
break;
}
}
if (ans == 1)puts("-");
else puts("+");
}
}