Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
62697 张江鹏 字符串中最大的数字 C++ Compile Error 0 MS 0 KB 1143 2023-12-24 17:55:19

Tests(0/0):


Code:

public string GetMaxLenNumber(string inputStr) { //将字符串中的字符存放到数组中,便于处理 char[] strCharArray = inputStr.ToCharArray(); //开始处理的位置 int startPos = 0; //当前处理的字符长度 int tempCharCount = 0; //数字的最长长度 int maxLen = 0; //数组的总长度 int len = strCharArray.Length; int pos = 0; while (startPos < len) { //循环中的临时最大长度 int tempMax = 0; while (tempCharCount + startPos < len) { //开始处理的字符 char c = strCharArray[tempCharCount + startPos]; if (char.IsNumber(c)) { //如果是数字 tempMax++; if (tempMax > maxLen) { maxLen = tempMax; pos = startPos; } } else { //不是数字 tempMax = 0; startPos++; break; } tempCharCount++; } if (startPos + tempCharCount == len) { break; } tempCharCount = 0; } string s = inputStr.Substring(pos, maxLen); return s; }


Run Info:

Main.cc:1:1: error: expected unqualified-id before 'public'
 public string GetMaxLenNumber(string inputStr)
 ^