Created
April 21, 2012 14:44
-
-
Save pogin503/2437463 to your computer and use it in GitHub Desktop.
aizu online judge link: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002
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 <iostream> | |
#include <string> | |
#include <cassert> | |
#include <sstream> | |
#include <vector> | |
#include "math.h" | |
template<typename T> | |
T string2binary(const std::string& text, int base) | |
{ | |
assert(base == 8 || base == 10 || base == 16); | |
std::istringstream is(text); | |
T value; | |
switch (base) { | |
case 8: is >> std::oct >> value; break; | |
case 10: is >> value; break; | |
case 16: is >> std::hex >> value; break; | |
default: ; | |
} | |
return value; | |
} | |
void splitstring(const std::string& data, const char* delimiter, std::vector<std::string>& result) | |
{ | |
result.clear(); | |
if( data.empty() ) return; | |
std::string::size_type pos = 0; | |
std::string::size_type new_pos; | |
while( ( new_pos = data.find( delimiter, pos)) != std::string::npos ){ | |
result.push_back( data.substr( pos, new_pos-pos ) ); | |
pos = new_pos+1; | |
} | |
result.push_back( data.substr( pos ) ); | |
} | |
int numberOfDigit(int num){ | |
return (int)log10(num) + 1; | |
} | |
void print1DItem(std::vector<int>& vec){ | |
std::vector<int>::iterator it = vec.begin(); | |
for(; it != vec.end(); it++){ | |
std::cout << *it << std::endl; | |
} | |
} | |
int main(){ | |
using namespace std; | |
int ii = 0, count = 0; | |
vector<int> result; | |
std::string line; | |
while(std::getline(cin, line)){ | |
// char in[256]; | |
// cin.getline(in, 256); | |
// std::string str = in; | |
if(line.size() == 0) break; | |
// cout << line.size() << endl; | |
std::vector<std::string> vec; | |
// スペースをデリミターにして2つに分割 | |
splitstring(line, " ", vec); | |
// 2つの数字を足し合わせる | |
// vector<string>::iterator it = vec.begin(); | |
// for(; it != vec.end(); it++){ | |
// cout << *it << endl; | |
// } | |
// cout << endl; | |
int sum = string2binary<int>(vec[ii], 10) | |
+ string2binary<int>(vec[ii + 1], 10); | |
// cout << numberOfDigit(sum) << endl; | |
result.push_back(sum); | |
// count++; | |
} | |
std::vector<int>::iterator it = result.begin(); | |
for(; it != result.end(); it++){ | |
cout << numberOfDigit(*it) << endl; | |
// cout << numberOfDigit(*it); | |
} | |
// cout << numberOfDigit(*it); | |
} |
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 <cassert> | |
#include <sstream> | |
#include <set> | |
#include <iostream> | |
template<typename T> | |
T string2binary(const std::string& text, int base) | |
{ | |
assert(base == 8 || base == 10 || base == 16); | |
std::istringstream is(text); | |
T value; | |
switch (base) { | |
case 8: is >> std::oct >> value; break; | |
case 10: is >> value; break; | |
case 16: is >> std::hex >> value; break; | |
default: ; | |
} | |
return value; | |
} | |
int main(){ | |
std::string str; | |
std::set<int> hills; | |
while(getline(std :: cin, str)){ | |
if(str.size() == 0) break; | |
// if(str == 0 || str == NULL)break; | |
hills.insert(string2binary<int>(str, 10)); | |
} | |
std::set<int>::reverse_iterator it = hills.rbegin(); | |
for(int ii = 0; ii < 3; ii++){ | |
std::cout << *it++ << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment