Skip to content

Instantly share code, notes, and snippets.

@pogin503
Created April 21, 2012 14:44
Show Gist options
  • Save pogin503/2437463 to your computer and use it in GitHub Desktop.
Save pogin503/2437463 to your computer and use it in GitHub Desktop.
#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);
}
#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