假设电话收费标准为: (1)国际长途1.00元/分钟,(2) 国内长途0.60元/分钟,(3)市话前3分钟0.20元,3分钟以后0.10元/分钟。现假设某话单文件中每条话单包含如下信息:通话日期(10

你好,帮我做个C语言题目
在这里插入图片描述

你好,我是Assistant。很高兴为您做题。

请提供题目的完整题面,并提供任何相关的输入、输出、约束条件等信息。

如果您有任何其他问题,请随时与我联系。我将竭诚为您服务。

897354667@qq.com
假设电话收费标准为: (1)国际长途1.00元/分钟,(2) 国内长途0.60元/分钟,(3)市话前3分钟0.20元,3分钟以后0.10元/分钟。现假设某话单文件中每条话单包含如下信息:通话日期(10位字符)、主叫码(11位字符) 、被叫码(12位字符)、起始时间(8位字符)、 通话时长(整型,单位:秒),要求从话单文件中读取话单信息,计算每条话单的话费,并按话费从高到低输出所有的话单信息。

话单格式:

2020-05-06 6786210101068790908 10:20:50 552020-05-07 13707103274 00156789035 21:30:20 125

您好,根据您给出的题目要求,我给出如下的C语言代码:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// 每条通话记录的结构体
typedef struct {
    char date[11]; // 通话日期
    char caller[12]; // 主叫号码
    char callee[13]; // 被叫号码
    char start_time[9]; // 起始时间
    int duration; // 通话时长(单位:秒)
    double charge; // 话费(单位:元)
} Record;

// 比较两条通话记录的话费大小,用于排序
int compare(const void *a, const void *b) {
    double diff = (*(Record *)b).charge - (*(Record *)a).charge;
    if (diff > 0) {
        return 1;
    } else if (diff < 0) {
        return -1;
    } else {
        return 0;
    }
}

int main() {
    Record records[100]; // 存储通话记录的数组
    int n = 0; // 记录条数
    char line[100]; // 读取每一行的数据
    while (fgets(line, sizeof(line), stdin)) {
        // 从读入的字符串中提取出每条通话记录的数据
        sscanf(line, "%s%s%s%s%d", records[n].date, records[n].caller, records[n].callee, records[n].start_time, &records[n].duration);

        // 计算话费
        // 判断是否为市话
        if (records[n].caller[0] == '0' && records[n].caller[1] == '1' && records[n].caller[2] == '3' && records[n].caller[3] == '7') {
            // 市话,前3分钟每分钟0.2元
            if (records[n].duration <= 3 * 60) {
                records[n].charge = records[n].duration * 0.2 / 60.0;
            } else {
                // 3分钟以后每分钟0.1元
                records[n].charge = 3 * 0.2 / 60.0 + (records[n].duration - 3 * 60) * 0



#include <stdio.h>
#include <string.h>
#include <stdlib.h>

// 每条通话记录的结构体
typedef struct {
    char date[11]; // 通话日期
    char caller[12]; // 主叫号码
    char callee[13]; // 被叫号码
    char start_time[9]; // 起始时间
    int duration; // 通话时长(单位:秒)
    double charge; // 话费(单位:元)
} Record;

// 比较两条通话记录的话费大小,用于排序
int compare(const void *a, const void *b) {
    double diff = (*(Record *)b).charge - (*(Record *)a).charge;
    if (diff > 0) {
        return 1;
    } else if (diff < 0) {
        return -1;
    } else {
        return 0;
    }
}

int main() {
    Record records[100]; // 存储通话记录的数组
    int n = 0; // 记录条数
    char line[100]; // 读取每一行的数据
    while (fgets(line, sizeof(line), stdin)) {
        // 从读入的字符串中提取出每条通话记录的数据
        sscanf(line, "%s%s%s%s%d", records[n].date, records[n].caller, records[n].callee, records[n].start_time, &records[n].duration);

        // 计算话费
        // 判断是国内长途还是国际长途
        if (records[n].callee[0] == '0') {
            records[n].charge = records[n].duration * 0.6 / 60.0; // 国内长途,每分钟0.6元
        } else {
            records[n].charge = records[n].duration * 1.0 / 60.0; // 国际长途,每分钟1.0元
        }
        // 判断是否为市话
        if (records[n].caller[0] == '0' && records[n].caller[1] == '1' && records[n].caller[2] == 					    	 '3' && records[n].caller[3] == '7') {
        // 市话,前3分钟每分钟0.2元
        if (records[n].duration <= 3 * 60) {
        records[n].charge = records[n].duration * 0.2 / 60.0;
        } else {
        // 3分钟以后每分钟0.1元
        records[n].charge = 3 * 0.2 / 60.0 + (records[n].duration - 3 * 60) * 0.1 / 60.0;
        }
        } else {
        // 非市话,按照国内长途或国际长途的标准计算话费
        if (records[n].callee[0] == '0') {
        records[n].charge = records[n].duration * 0.6 / 60.0; // 国内长途,每分钟0.6元
        } else {
        records[n].charge = records[n].duration * 1.0 / 60.0; // 国际长途,每分钟1.0元
        }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东方-教育技术博主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值