Advertisement
Nbrevu

Tuenti Contest 6 (Pablo Moreno)

Jun 20th, 2011
1,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. /*
  2.     Author: Pablo Moreno Olalla
  3.     Email address: darthbrevu@yahoo.es
  4. */
  5. #include <cstdio>
  6. #include <string>
  7. #include <sstream>
  8. #include <iostream>
  9.  
  10. using namespace std;
  11.  
  12. unsigned long long leds[]={6,2,5,5,4,5,6,3,7,6};
  13. unsigned long long accum[]={6,8,13,18,22,27,33,36,43,49};
  14.  
  15. unsigned long long times[]={36000,3600,600,60,10};
  16.  
  17. unsigned long long accum2[6];
  18.  
  19. inline void initA() {
  20.     accum2[5]=accum[9]; //10s
  21.     accum2[4]=6*accum2[5]+10*accum[5];  //1m
  22.     accum2[3]=10*accum2[4]+60*accum[9]; //10m
  23.     accum2[2]=6*accum2[3]+600*accum[5]; //1h
  24.     accum2[1]=10*accum2[2]+3600*accum[9];   //10h
  25.     accum2[0]=24*accum2[2]+accum[1]*36000+leds[2]*14400+accum[9]*7200+accum[3]*3600;
  26. }
  27.  
  28. unsigned long long totalLeds(unsigned secs) {
  29.     unsigned long long d=secs/86400;
  30.     unsigned long long res=accum2[0]*d;
  31.     secs%=86400;
  32.     unsigned long long count;
  33.     for (int i=0;i<5;++i)   {
  34.         count=secs/times[i];
  35.         secs%=times[i];
  36.         res+=count*accum2[i+1]+leds[count]*(secs+1);
  37.         if (count>0) res+=times[i]*accum[count-1];
  38.     }
  39.     return res+accum[secs];
  40. }
  41.  
  42. int main(int argc,char **argv)  {
  43.     //The first two lines are not strictly necessary, but make the code a little more handy.
  44.     if (argc>=2) freopen(argv[1],"r",stdin);
  45.     if (argc>=3) freopen(argv[2],"w",stdout);
  46.     initA();
  47.     string tmp;
  48.     unsigned long long ull;
  49.     do  {
  50.         getline(cin,tmp);
  51.         istringstream iss(tmp);
  52.         iss>>ull;
  53.         if (!iss.fail()) cout<<totalLeds(ull)<<endl;
  54.     }   while (!cin.eof());
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement