[MM70-易] Simple Recursion - Find the maximum value of a number list
Time Limit: 1 seconds
Problem Description :
To find the maximum value M in a list of N 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 < N < 100.
Input File Format :
The input consists of a list of N integer numbers (space-separated), and 0 < N < 100 .
Output Format :
The output contains one integer number M , M is the largest integer of the integer list and 0 < M < 1000.
Example :
Problem Description :
To find the maximum value M in a list of N 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 < N < 100.
Input File Format :
The input consists of a list of N integer numbers (space-separated), and 0 < N < 100 .
Output Format :
The output contains one integer number M , M is the largest integer of the integer list and 0 < M < 1000.
Example :
Sample Input | Sample Output |
1 2 3 4 5 | 5 |
3 3 3 3 3 3 3 3 3 3 3 3 | 3 |
345 678 891 999 567 11 | 999 |
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <sstream>
- #include <stdio.h>
- #include <ctype.h>
- #include <cmath>
- using namespace std;
- int main() {
- // [MM70-易] Simple Recursion - Find the maximum value of a number list
- string text;
- while(getline(cin, text))
- {
- int max = -1;
- stringstream ss(text);
- string token;
- while (getline(ss, token, ' '))
- {
- if(stoi(token) > max)
- {
- max = stoi(token);
- }
- }
- cout << max << endl;
- }
- return 0;
- }
沒有留言:
張貼留言