UVA ONLINE JUDGE
PROBLEM 11636
Hello World!
Problem link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2683
Solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int n,j;
for(int i=1;; i++)
{
cin>>n;
if(n<0) break;
for(j=0; j<=n; j++)
{
if(pow(2,j)==n)
{
printf("Case %d: %d\n",i,j);
break;
}
if(pow(2,j+1)>n)
{
printf("Case %d: %d\n",i,j+1);
break;
}
}
}
return 0;
}
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int n,j;
for(int i=1;; i++)
{
cin>>n;
if(n<0) break;
for(j=0; j<=n; j++)
{
if(pow(2,j)==n)
{
printf("Case %d: %d\n",i,j);
break;
}
if(pow(2,j+1)>n)
{
printf("Case %d: %d\n",i,j+1);
break;
}
}
}
return 0;
}
//Language:C++;
No comments:
Post a Comment