00001 00010 #define __cplusplus__ 00011 #ifndef __UTILS__ 00012 #define __UTILS__ 00013 00014 #include<iostream> 00015 #include<istream> 00016 #include<fstream> 00017 #include<string> 00018 #include<vector> 00019 #include<sstream> 00020 #include <cmath> 00021 00022 00023 using namespace std; 00024 00041 template<typename T> T fromString(const std::string& s) { 00042 std::istringstream is(s); 00043 T t; 00044 is >> t; 00045 return t; 00046 } 00047 00066 template<typename T> std::string toString(const T& t) { 00067 std::ostringstream s; 00068 s << t; 00069 return s.str(); 00070 } 00071 00072 00077 template<typename T> void ReadVector(istream & is , std::vector<T>& tvec) { 00078 uint sz=0; 00079 is >> sz; 00080 tvec.clear(); 00081 tvec.resize(sz); 00082 for( uint i=0 ; i < sz ; i++ ) { 00083 T t ; 00084 is >> t ; 00085 tvec[i]=t; 00086 } 00087 } 00088 00089 00094 template<typename T> void WriteVector(ostream & os , const std::vector<T> & tvec) { 00095 uint sz= tvec.size(); 00096 os << sz; 00097 for( uint i=0 ; i < sz ; i++ ) { 00098 os << " " << tvec[i] ; 00099 } 00100 os << endl; 00101 } 00102 00103 00104 char upper(char c); 00105 00106 00107 #endif