Problem L: 短信计费

103 篇文章 11 订阅

2018年C语言考试题目
Problem L: 短信计费
Description
现有手机短信服务商提供如下服务:每条短信长度限定在1~30个字符之内,客户每次发送的信息最多不超过500个字符,信息中每30个字符计算为1条短信,每月月租1元包15条短信,超过15条每条短信收费0.1元,(字符数为0的)空信息不计费。

现给出客户一个月发送的全部短信,编程计算出客户花费(含月租费)。

Input
输入为多行,至EOF结束。每行为一条信息(可能是多条短信),除了换行符“\n”之外,其他字符都是信息的内容。

Output
输出客户本月花费,精确到小数点后1位。

Sample Input

Who is that girl?
Where?
Over there,under the big tree.
Oh, that's my sister.She often takes a light blue blouse and a pink skirk.
What's on her hair?
It's an accessory.
What colour is it?
It's pink.She likes pink very much.
How do you like your sister?
She is cute and lovely,and she works hard.
I got a ticket yesterday.
You ran a red light.
He nearly ran into the bus.
Don't take it to heart. You'll never happen again.
Take it easy. There must be some ways to compensate for it.
Don't be so upset. Everything will be OK.
It's really hard for you.
Thank you!It won't happen again.
Sample Output
2.1

思路:

注意count<15时输出1.0;
count>15的部分按0.1每条记录收费
空消息不计入收费S[0]’\0’ || S[0]’\n’

ans:

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

int cell(char *s)
{

    if(s[0]=='\0'||s[0]=='\n')return 0;
    if(strlen(s)==0)return 0;

    int ans=strlen(s)/30;
    if(ans*30==strlen(s))return ans;
    else                 return ans+1;
}

int main()
{
    char s[501];
    int count=0;
    double sum=1.0;
    while(gets(s)!=NULL){
        count+=cell(s);
    }
    if(count>15)sum+=(count-15)*0.1;
    printf("%.1lf",sum);
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值