找出字符串中最大的数字
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
    char str[80];
    //int arr[80], temp, pos = 0, n = 0, i, max = 0, flag;
	int temp;
	int pos = 0;
	bool flag ;
	int maxnumer = 0;
    printf("请输入字符串:\n");
    scanf("%s", str);
    while (str[pos] != '\0')
    {
        temp = 0;
		flag = false;//设置是否有整数的标志
        while (str[pos] >= '0' && str[pos] <= '9')
        {
            temp = 10 * temp + str[pos] - '0';
            pos++;
            flag = 1;
        }
        if (flag)
        {
            if (temp >maxnumer)
            {
				maxnumer = temp;
            }
            pos--;//由于在存整数的时候多走了一步,要减1
        }
        pos++;
    }
	cout << maxnumer <<endl;
}
    一切源于对计算机的热爱
 
                    
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号