Advertisement
Dennnhhhickk

Untitled

Oct 6th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <queue>
  4. #include <iomanip>
  5.  
  6. #define mp make_pair
  7.  
  8. using namespace std;
  9.  
  10. typedef long long ll;
  11. typedef unsigned long long ull;
  12. typedef long double ld;
  13. typedef ld typ;
  14. typedef string str;
  15.  
  16. struct point
  17. {
  18. ld x, y;
  19. };
  20.  
  21. struct vec
  22. {
  23. ld a, b;
  24. };
  25.  
  26. struct line
  27. {
  28. ld a, b, c;
  29. };
  30.  
  31. /*istream& operator>> ( istream& in, point& p)
  32. {
  33. in >> p.x >> p.y;
  34. return in;
  35. }
  36.  
  37. ostream& operator<<(ostream& out, point& p)
  38. {
  39. out << p.x << ' ' << p.y;
  40. return out;
  41. }*/
  42.  
  43. void build(ll, ll, ll);
  44. ll _max(ll, ll, ll, ll, ll);
  45. void update(ll, ll, ll, ll, ll, ll);
  46. typ sqr(typ);
  47. void start();
  48. void extended(int);
  49. point n_point(point, point);
  50. vec mv(point, point);
  51. line ml(point, point);
  52. typ croos(vec, vec);
  53. typ skalar(vec, vec);
  54.  
  55. int a[100000], d[400000], updateb[400000];
  56.  
  57. ll check(str s)
  58. {
  59. ll sum = 0, p = 1;
  60. for (int i = 0; i < s.size(); i++)
  61. {
  62. if (s[i] == '1')
  63. sum += p;
  64. p *= 2;
  65. }
  66. //cout << sum << endl;
  67. return sum;
  68. }
  69.  
  70. char out(ll s)
  71. {
  72. if (s <= 9)
  73. return (char)(s + '0');
  74. if (s == 10)
  75. return 'A';
  76. if (s == 11)
  77. return 'B';
  78. if (s == 12)
  79. return 'C';
  80. if (s == 13)
  81. return 'D';
  82. if (s == 14)
  83. return 'E';
  84. if (s == 15)
  85. return 'F';
  86. }
  87.  
  88. str form(str s)
  89. {
  90. while (s.size() != 1)
  91. {
  92. if (s[0] == '0' && s[1] == '0')
  93. s.erase(0, 1);
  94. else
  95. return s;
  96. }
  97. return s;
  98. }
  99.  
  100. char ch(char a)
  101. {
  102. ll n = (int)(a - '0');
  103. n++;
  104. return (char)(n + '0');
  105. }
  106.  
  107. int main()
  108. {
  109. start();
  110.  
  111. str s;
  112. cin >> s;
  113. ll n, p;
  114. cin >> n;
  115. p = n;
  116. ll fnd = 0;
  117. for (int i = 0; i < s.size(); i++)
  118. if (s[i] == '.')
  119. {
  120. fnd = i;
  121. break;
  122. }
  123. if (n > 0)
  124. {
  125. n += fnd;
  126. if (s[n + 1] >= '5')
  127. for (int i = n; i >= -1; i--)
  128. {
  129. if (i == -1)
  130. {
  131. s = "1" + s;
  132. n++;
  133. break;
  134. }
  135. if (i == fnd)
  136. continue;
  137. if (s[i] == '9')
  138. s[i] = '0';
  139. else
  140. {
  141. s[i] = ch(s[i]);
  142. break;
  143. }
  144. }
  145. for (int i = 0; i <= n; i++)
  146. cout << s[i];
  147. cout << endl;
  148. return 0;
  149. }
  150. if (n == 0)
  151. {
  152. n = fnd;
  153. if (s[n + 1] >= '5')
  154. for (int i = n; i >= -1; i--)
  155. {
  156. if (i == -1)
  157. {
  158. s = "1" + s;
  159. n++;
  160. break;
  161. }
  162. if (i == fnd)
  163. continue;
  164. if (s[i] == '9')
  165. s[i] = '0';
  166. else
  167. {
  168. s[i] = ch(s[i]);
  169. break;
  170. }
  171. }
  172. for (int i = 0; i < n; i++)
  173. cout << s[i];
  174. cout << endl;
  175. return 0;
  176. }
  177. /*if (n < 0 && -n > fnd)
  178. return cout << 0 << endl, 0;
  179. /*if (-n == fnd && s[0] >= '5')
  180. {
  181. cout << 1;
  182. for (int i = 0; i < fnd; i++)
  183. cout << 0;
  184. cout << endl;
  185. return 0;
  186. }
  187. if (-n == fnd)
  188. return cout << 0 << endl, 0;*/
  189. if (n < 0)
  190. {
  191. n = fnd + p;
  192. if (s[n] >= '5')
  193. for (int i = n-1; i >= -1; i--)
  194. {
  195. if (i == -1)
  196. {
  197. s = "1" + s;
  198. n++;
  199. break;
  200. }
  201. if (i == fnd)
  202. continue;
  203. if (s[i] == '9')
  204. s[i] = '0';
  205. else
  206. {
  207. //cout << 1 << endl;
  208. s[i] = ch(s[i]);
  209. break;
  210. }
  211. }
  212. for (int i = 0; i < s.size(); i++)
  213. if (s[i] == '.')
  214. {
  215. fnd = i;
  216. break;
  217. }
  218. for (int i = fnd-1, k = 0; i >= 0 && k != -p; i--, k++)
  219. {
  220. s[i] = '0';
  221. }
  222. s = form(s);
  223. for (int i = 0; i < s.size(); i++)
  224. if (s[i] == '.')
  225. {
  226. fnd = i;
  227. break;
  228. }
  229. for (int i = 0; i < fnd; i++)
  230. cout << s[i];
  231. cout << endl;
  232. return 0;
  233. }
  234. return 0;
  235. }
  236.  
  237. void build(ll v, ll tl, ll tr)
  238. {
  239. if (tl == tr)
  240. d[v] = a[tl];
  241. else
  242. {
  243. ll tm = (tl + tr) / 2;
  244. build(v * 2, tl, tm);
  245. build(v * 2 + 1, tm + 1, tr);
  246. d[v] = max(d[v * 2], d[v * 2 + 1]);
  247. }
  248. }
  249.  
  250. ll _max(ll v, ll tl, ll tr, ll l, ll r)
  251. {
  252. if (l > r)
  253. return 0;
  254. if (tl == l && tr == r)
  255. return d[v] + updateb[v];
  256. ll tm = (tl + tr) / 2;
  257. return max(_max(v * 2, tl, tm, l, min(r, tm)), _max(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)) + updateb[v];
  258. }
  259.  
  260. void update(ll v, ll tl, ll tr, ll l, ll r, ll s)
  261. {
  262. if (l > r)
  263. return;
  264. if (tl == l && tr == r)
  265. {
  266. updateb[v] += s;
  267. return;
  268. }
  269. ll tm = (tl + tr) / 2;
  270. update(v * 2, tl, tm, l, min(r, tm), s);
  271. update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, s);
  272. }
  273.  
  274. ld sqr(ld a)
  275. {
  276. return a * a;
  277. }
  278.  
  279. void start()
  280. {
  281. ios::sync_with_stdio(0);
  282. cin.tie(0);
  283. cout.tie(0);
  284. }
  285.  
  286. void extended(int n)
  287. {
  288. cout << setprecision(n) << fixed;
  289. }
  290.  
  291. point n_point(point a, point b)
  292. {
  293. point n;
  294. n.x = a.x;
  295. n.y = b.y;
  296. return n;
  297. }
  298.  
  299. vec mv(point st, point fn)
  300. {
  301. vec v;
  302. v.a = fn.x - st.x;
  303. v.b = fn.y - st.y;
  304. return v;
  305. }
  306.  
  307. line ml(point a, point b)
  308. {
  309. line l;
  310. l.a = b.y - a.y;
  311. l.b = a.x - b.x;
  312. l.c = -l.a * a.x - l.b * a.y;
  313. return l;
  314. }
  315.  
  316. typ skalar(vec a, vec b)
  317. {
  318. return a.a * b.a + a.b * b.b;
  319. }
  320.  
  321. typ cross(vec a, vec b)
  322. {
  323. return a.a * b.b - a.b * b.a;
  324. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement