File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ all :
2+ gcc -O1 -o test calculator.c
Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ #include <stdlib.h>
3+
4+
5+ int brokenCalc (int X , int Y )
6+ {
7+ int step = 0 ;
8+ while (X < Y ) {
9+ Y = Y & 1 ? Y + 1 : Y / 2 ;
10+ step ++ ;
11+ }
12+ step += X - Y ;
13+ return step ;
14+ }
15+
16+ int main (int argc , char * * argv )
17+ {
18+ if (argc != 3 ) {
19+ fprintf (stderr , "Usage: ./test x y" );
20+ exit (-1 );
21+ }
22+
23+ int x = atoi (argv [1 ]);
24+ int y = atoi (argv [2 ]);
25+ printf ("%d\n" , brokenCalc (x , y ));
26+ return 0 ;
27+ }
Original file line number Diff line number Diff line change 1+ class Solution {
2+ public:
3+ int brokenCalc (int X, int Y) {
4+ int step = 0 ;
5+ while (X < Y) {
6+ Y = Y & 1 ? Y + 1 : Y / 2 ;
7+ step++;
8+ }
9+ step += X - Y;
10+ return step;
11+ }
12+ };
You can’t perform that action at this time.
0 commit comments