一、题目链接
http://noi.openjudge.cn/ch0112/02/
二、解题思路(Java)
三、解题思路(C++)
四、Java程序
import java.util.Scanner;
public class Main {
public double cost(int[] messages) {
double ans = 0;
for (int e : messages) {
ans = ans + 0.1 * Math.ceil(e / 70.0);
}
return ans;
}
public static void main(String[] args) {
Main test = new Main();
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] messages = new int[n];
for (int i = 0; i < n; i++) {
messages[i] = input.nextInt();
}
System.out.printf("%.1f", test.cost(messages));
}
}
五、C++程序
#include <iostream>
#include <cmath>
using namespace std;
double cost(int messages[], int n)
{
double ans = 0;
for (int i = 0; i < n; i++)
{
ans = ans + 0.1 * ceil(messages[i] / 70.0);
}
return ans;
}
int main()
{
int n;
cin >> n;
int messages[n];
for (int i = 0; i < n; i++)
{
cin >> messages[i];
}
printf("%.1f", cost(messages, n));
return 0;
}