| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 73389 | LJY | 字符串中最大的数字 | C++ | Accepted | 0 MS | 272 KB | 597 | 2024-05-18 19:03:46 |
#include <iostream> #include <string> #include <algorithm> // For std::max function using namespace std; int main() { string input; cin >> input; // 如果输入的数是负数,跳过第一个字符(即负号) int startIndex = input[0] == '-' ? 1 : 0; char maxDigit = '0'; // 遍历字符串寻找最大的数字字符 for (int i = startIndex; i < input.length(); ++i) { if (input[i] >= '0' && input[i] <= '9') { maxDigit = max(maxDigit, input[i]); } } cout << maxDigit << endl; return 0; }