Last active
August 29, 2015 14:11
-
-
Save ilyapopov/1006a5a5ccdfdde85935 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <cstdio> | |
int max_iostream(std::istream & f) | |
{ | |
int x; | |
int max = -1; | |
while(f >> x) | |
max = std::max(x, max); | |
return max; | |
} | |
int max_iostream_iss(std::istream & f) | |
{ | |
int x; | |
int max = -1; | |
std::string line; | |
while (std::getline(f, line)) | |
{ | |
std::istringstream iss(line); | |
if(! (iss >> x)) | |
break; | |
max = std::max(x, max); | |
} | |
return max; | |
} | |
int max_iostream_iss_2(std::istream & f) | |
{ | |
int x; | |
int max = -1; | |
std::string line; | |
std::istringstream iss(line); | |
while (std::getline(f, line)) | |
{ | |
iss.clear(); // Сбрасываем флаги ошибок | |
iss.str(line); // Задаём новый буфер | |
if(! (iss >> x)) | |
break; | |
max = std::max(x, max); | |
} | |
return max; | |
} | |
int max_scanf() | |
{ | |
int x; | |
int max = -1; | |
while (scanf("%d", &x) == 1) | |
{ | |
max = std::max(x, max); | |
} | |
return max; | |
} | |
bool read_int(int & out) | |
{ | |
int c = getchar(); | |
int x = 0; | |
int neg = 0; | |
for (; !('0'<=c && c<='9') && c != '-'; c = getchar()) | |
{ | |
if (c == EOF) | |
return false; | |
} | |
if (c == '-') | |
{ | |
neg = 1; | |
c = getchar(); | |
} | |
if (c == EOF) | |
return false; | |
for (; '0' <= c && c <= '9' ; c = getchar()) | |
{ | |
x = x*10 + c - '0'; | |
} | |
out = neg ? -x : x; | |
return true; | |
} | |
int max_getchar() | |
{ | |
int x; | |
int max = -1; | |
while(read_int(x)) | |
max = std::max(x, max); | |
return max; | |
} | |
bool read_int_unlocked(int & out) | |
{ | |
int c = getchar_unlocked(); | |
int x = 0; | |
int neg = 0; | |
for (; !('0'<=c && c<='9') && c != '-'; c = getchar_unlocked()) | |
{ | |
if (c == EOF) | |
return false; | |
} | |
if (c == '-') | |
{ | |
neg = 1; | |
c = getchar_unlocked(); | |
} | |
if (c == EOF) | |
return false; | |
for (; '0' <= c && c <= '9' ; c = getchar_unlocked()) | |
{ | |
x = x*10 + c - '0'; | |
} | |
out = neg ? -x : x; | |
return true; | |
} | |
int max_getchar_unlocked() | |
{ | |
int x; | |
int max = -1; | |
while(read_int_unlocked(x)) | |
max = std::max(x, max); | |
return max; | |
} | |
int max_stoi(std::istream & f) | |
{ | |
int max = -1; | |
std::string line; | |
while (std::getline(f, line)) | |
{ | |
int x = std::stoi(line); | |
max = std::max(x, max); | |
} | |
return max; | |
} | |
int main() | |
{ | |
//std::ios::sync_with_stdio(false); | |
std::cout << max_scanf() << std::endl; | |
//std::cout << max_iostream(std::cin) << std::endl; | |
//std::cout << max_iostream_iss(std::cin) << std::endl; | |
//std::cout << max_iostream_iss_2(std::cin) << std::endl; | |
//std::cout << max_getchar() << std::endl; | |
//std::cout << max_getchar_unlocked() << std::endl; | |
//std::cout << max_stoi(std::cin) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment