2018年1月12日 星期五

[MM70-易] Simple Recursion - Find the maximum value of a number list(C++)

[MM70-易] Simple Recursion - Find the maximum value of a number list

Time Limit: 1 seconds
Problem Description :
To find the maximum value in a list of integer numbers (all the integer numbers are greater than 0 and smaller than 1000 and not including 0 and 1000, all numbers are not unique), and 0 < < 100.
Input File Format :
The input consists of a list of integer numbers (space-separated), and 0 < < 100 .
Output Format :
The output contains one integer number is the largest integer of the integer list and 0 < < 1000.
Example :

Sample InputSample Output
1 2 3 4 55
3 3 3 3 3 3 3 3 3 3 3 33
345 678 891 999 567 11999

  1. #include <iostream>  
  2. #include <algorithm>  
  3. #include <string>  
  4. #include <sstream>  
  5. #include <stdio.h>  
  6. #include <ctype.h>  
  7. #include <cmath>  
  8. using namespace std;  
  9.   
  10. int main() {  
  11.     // [MM70-易] Simple Recursion - Find the maximum value of a number list  
  12.     string text;  
  13.     while(getline(cin, text))  
  14.     {  
  15.         int max = -1;  
  16.         stringstream ss(text);  
  17.         string token;  
  18.         while (getline(ss, token, ' '))  
  19.         {  
  20.             if(stoi(token) > max)  
  21.             {  
  22.                 max = stoi(token);  
  23.             }  
  24.         }  
  25.         cout << max << endl;  
  26.     }  
  27.     return 0;  
  28. }  

沒有留言:

張貼留言