1688 just follow the problem description
This commit is contained in:
		
							
								
								
									
										24
									
								
								1688-20231205-pass/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								1688-20231205-pass/main.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| #include<stdcpp.h> | ||||
| using namespace std; | ||||
| class Solution{ | ||||
|     public: | ||||
|     int numberOfMatches(int n){ | ||||
|         int sum = 0; | ||||
|         while(n!=1){ | ||||
|             sum+=n/2; | ||||
|             if(n%2) n+=1; | ||||
|             n/=2; | ||||
|         } | ||||
|         return sum; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| int main(){ | ||||
|     Solution sol; | ||||
|     int n; | ||||
|     n = 7; | ||||
|     cout<<sol.numberOfMatches(n)<<endl; | ||||
|     n = 14; | ||||
|     cout<<sol.numberOfMatches(n)<<endl; | ||||
|     return 0; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user