洛谷入门篇的相关题解 | 您所在的位置:网站首页 › 洛谷p1424 › 洛谷入门篇的相关题解 |
CF616A Comparing Two Long Integers
思路: 因为数字可能含有前导零,所以先对两个数字进行去除前导零的操作,操作后的两个数字如果位数相同,再逐位比较,否则,位数多的那个数字大于位数少的那个数字. 参考代码: #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string a, b; cin >> a >> b; int mark = 0; for (auto j : a) { if (j == '0') mark++; else break; } if (mark != 0) a = a.substr(mark); mark = 0; for (auto j : b) { if (j == '0') mark++; else break; } if (mark != 0) b = b.substr(mark); if (a.size() != b.size()) { cout b[i]) { cout |
CopyRight 2018-2019 实验室设备网 版权所有 |