Guest User

c++ magic

a guest
Feb 23rd, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <iostream>
  6. #include <string>
  7. #include <set>
  8. #include <map>
  9. #include <vector>
  10. #include <queue>
  11. #include <typeinfo>
  12.  
  13. using namespace std;
  14.  
  15. typedef unsigned int uint;
  16. typedef unsigned long long ull;
  17. typedef long long ll;
  18. typedef long double llf;
  19. typedef double lf;
  20. typedef float sf;
  21.  
  22. typedef pair<ull,ull> para;
  23.  
  24. #define forn(i,n) for(auto i=(n)-(n);i<(n);++i)
  25. #define forab(i,a,b) for(auto i=(a)+(b)-(b);i<(b);++i)
  26. #define fornd(i,n) for(auto i=(n);i--;)
  27.  
  28. #define _tc(x,y) (typeid(x)==typeid(y) || typeid(x)==typeid(const y) || typeid(x)==typeid(y*) || typeid(x)==typeid(const y*))
  29. template<typename T>
  30. inline static const string fmtget(T x){
  31.     if(_tc(x,int)){
  32.         return "%i";
  33.     }else if(_tc(x,uint)){
  34.         return "%u";
  35.     }else if(_tc(x,long)){
  36.         return "%li";
  37.     }else if(_tc(x,unsigned long)){
  38.         return "%lu";
  39.     }else if(_tc(x,ll)){
  40.         return "%lli";
  41.     }else if(_tc(x,ull)){
  42.         return "%llu";
  43.     }else if(_tc(x,sf)){
  44.         return "%f";
  45.     }else if(_tc(x,lf)){
  46.         return "%lf";
  47.     }else if(_tc(x,llf)){
  48.         return "%Lf";
  49.     }else{
  50.         return "error";
  51.     }
  52. }
  53.  
  54. class fmt{
  55. public:
  56.     template <typename T,typename... Args>
  57.     fmt(const string& sp,const string& el,const T& x,const Args... args){s=fmtget(x)+sp+fmt(sp,el,args...).s;}
  58.     fmt(const string& sp,const string& el){s=el;}
  59.     string s;
  60. };
  61.  
  62. #define pr(...) printf(fmt(" ","\n",__VA_ARGS__).s.c_str(),__VA_ARGS__)
  63. #define sc(...) scanf(fmt("","",__VA_ARGS__).s.c_str(),__VA_ARGS__)
  64.  
  65. #define scn(a,n) forn(_read_index,(n)){sc((a)+_read_index);}
  66. #define scnn(a,n,type) uint n; sc(&(n)); type* (a)=new type[(n)]; scn(a,n);
  67.  
  68. #define prn(a,n) forn(_write_index,n){pr(a[_write_index]);}
  69.  
  70. template <typename T>
  71. int cmp_num(const void* a,const void* b){
  72.     return (*(T)a>*(T)b)-(*(T)a<*(T)b);
  73. }
  74.  
  75. #define sqsort(a,n) qsort(a,n,sizeof(*a),cmp_num<decltype(a)>)
  76. #define tqsort(a,n,type) qsort(a,n,sizeof(*a),cmp_num<type*>)
  77. #define fqsort(a,n,func) qsort(a,n,sizeof(*a),func);
  78.  
  79. #define sbsearch(key,a,n) (decltype(a))bsearch(&key,a,n,sizeof(*a),cmp_num<decltype(a)>)
  80. #define tbsearch(key,a,n,type) (decltype(a))bsearch(&key,a,n,sizeof(*a),cmp_num<type*>)
  81. #define fbsearch(key,a,n,func) (decltype(a))bsearch(&key,a,n,sizeof(*a),func)
  82.  
  83. int main(){
  84.     #ifdef noacm
  85.     freopen("input.txt","r",stdin);
  86.     //freopen("output.txt","w",stdout);
  87.     #endif
  88.    
  89.     scnn(a,n,uint);
  90.     sqsort(a,n);
  91.     prn(a,n);
  92.    
  93.     #ifdef noacm
  94.     fclose(stdin);
  95.     //fclose(stdout);
  96.     for(;;);
  97.     #endif
  98. }
Advertisement
Add Comment
Please, Sign In to add comment