#13527: 詭異的c++寫法


tn781927 (horse)

School : 國立臺中第一高級中學
ID : 74253
IP address : [223.141.80.140]
Last Login :
2025-01-24 10:42:18
d658. 11636 - Hello World! -- UVa11636 | From: [61.223.233.184] | Post Date : 2018-03-10 21:55

大約就是以2的平方去想:

#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
int n, count = 0;
while(scanf("%d",&n) != EOF){
if(n < 0) break;
int max = 0;
printf("Case %d:",++count);
for(int i=0;i<=14;i++){
if(pow(2,i) >= n){
max = i;
break;
}
}
printf(" %d",max);
printf("\n");
}
return 0 ;
}

 
#21622: Re:詭異的c++寫法


howard20060216@gmail.com (Howard)

School : 臺北市私立薇閣高級中學
ID : 106406
IP address : [140.113.136.218]
Last Login :
2024-12-16 16:30:48
d658. 11636 - Hello World! -- UVa11636 | From: [111.241.215.226] | Post Date : 2020-06-28 16:28

大約就是以2的平方去想:

#include
#include
using namespace std;

int main(){
int n, count = 0;
while(scanf("%d",&n) != EOF){
if(n < 0) break;
int max = 0;
printf("Case %d:",++count);
for(int i=0;i<=14;i++){
if(pow(2,i) >= n){
max = i;
break;
}
}
printf(" %d",max);
printf("\n");
}
return 0 ;
}

你寫的好不容易董

#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
    int N, count = 0;
    while (scanf("%d", &N) != EOF, N!=1){
        for (int i = 0; i <= 14; i++){
            if (pow(2, i) >= N){
                printf("Case %d: %d\n", ++count, i);
                break;
            }
        }
    }
    return 0;
}
 
ZeroJudge Forum