Advertisement
a53

Abba

a53
Jun 6th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. /**
  2. Problema: abba
  3. codificare sir prin
  4. inserare litera mijlocie
  5. */
  6. #include <fstream>
  7. #include <cstdlib>
  8. using namespace std;
  9. char x,y,dif_max,a,b,z,etape;
  10. int n=0;
  11. long long p;
  12. int main()
  13. {
  14. ifstream f("abba.in");
  15. ofstream g("abba.out");
  16. f>>x>>y;
  17. n=2;
  18. dif_max=labs(x-y);
  19. a=x;
  20. b=y;
  21. x=y;
  22. while(f>>y)
  23. {
  24. n++;
  25. z=labs(x-y);
  26. if(dif_max<z)
  27. {
  28. dif_max=z;
  29. a=x;
  30. b=y;
  31. }
  32. x=y;
  33. }
  34. if(b<a)
  35. swap(a,b);
  36. while(b-a>1)
  37. {
  38. a=(a+b)/2; ///cout<<a<<endl;
  39. etape++;
  40. }
  41. p= (long long)(1<<etape) * (n-1) + 1; /// 2^k(n-1)+1
  42. g<<int(etape)<<' '<<p;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement