Input output sample - 07Input Specification:Input file contains a series of lines. Each line contains one or more integers. Output Specification: For each line of input generate a line of output. This line contains an integer, which is the minimum number of input line. Sample Input: 10 5 7 9 10 3 4 7 8 Sample Output: 5 4 C Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #define size 1000 int main(){ char inputStr[size],*tempStr; int minNum,num; while(gets(inputStr)){ tempStr = strtok(inputStr," "); minNum = atoi(tempStr); while(tempStr!=NULL){ num = atoi(tempStr); if(num<minNum) minNum=num; tempStr=strtok(NULL," "); } printf("%d\n",minNum); } return 0; } C++ Code:
#include <iostream> #include <cstdlib> #include <sstream> #include <string> using namespace std; int main(){ string inputStr,tempStr; int minNum,num; while(getline(cin,inputStr)){ istringstream token(inputStr); token>>tempStr; minNum = atoi(tempStr.c_str()); while(token){ token >> tempStr; num = atoi(tempStr.c_str()); if(num<minNum) minNum=num; } cout<<minNum<<endl; } return 0; } |
||