24 lines
407 B
C++
24 lines
407 B
C++
#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;
|
|
} |