import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param petals int整型一维数组 花瓣数
* @return int整型
*/
public int petalsBreak (int[] petals) {
// write code here
int times = 0;
for(int num: petals) times += (num + 1) / 2;
return times;
}
} import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param petals int整型一维数组 花瓣数
* @return int整型
*/
public int petalsBreak (int[] petals) {
// write code here
int res = 0;
for(int petal: petals){
if(petal % 2 == 0) res += petal/2;
else res += petal/2 + 1;
}
return res;
}
} import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param petals int整型一维数组 花瓣数
* @return int整型
*/
public int petalsBreak (int[] petals) {
Scanner sc=new Scanner(System.in);
int count=0;
for (int i=0;i<petals.length;i++){
count=count+(int)Math.ceil((double)petals[i]/2.0);
}
return count;
}
} import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param petals int整型一维数组 花瓣数
* @return int整型
*/
public int petalsBreak (int[] petals) {
// write code here
int ans = 0;
for (int i = 0; i < petals.length; i++) {
ans += petals[i] / 2;
ans += petals[i] % 2;
}
return ans;
}
} class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param petals int整型vector 花瓣数
* @return int整型
*/
int petalsBreak(vector<int>& petals) {
int num;
int temp;
for(int i=0; i<petals.size(); i++){
if(petals[i] % 2){ // 不是偶数
num += (petals[i]+1) / 2;
}
else{ // 偶数
num += petals[i] / 2;
}
}
return num;
}
};