codeforces 339A.Helpful Maths B.Xenia and Ringroad 两水题

A.题意就是把字符串里面的数字按增序排列,直接上代码。

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

using namespace std;

int main()
{
    char s[1005];
    int num[105];
    while (scanf("%s" , s) != EOF)
    {
        int l = strlen(s);
        int t = 0;
        int cnt = 0;
        for (int i = 0; i <= l; i++)
        {
            if (s[i] == '+' || !s[i])
            {
                num[++cnt] = t;
                t = 0;
                continue;
            }
            t = t*10 + s[i]-'0';
        }
        sort(num+1, num+cnt+1);
        for (int i = 1; i < cnt; i++)
            printf("%d+", num[i]);
        printf("%d\n", num[cnt]);
    }
    return 0;
}



B.题意,有n个房子顺时针排成一圈,标号从1到n,只能顺时针走,要按次序到达规定的位置,从一个房子到旁边的房子需要1单位的时间,求总共要多长时间(注意要用64位整形)

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>

using namespace std;

int a[100005];

int main()
{
    int n, m;
    __int64 ans;
    a[0] = 1;
    while (scanf("%d %d", &n, &m) != EOF)
    {
        ans = 0;
        for (int i = 1; i <= m; i++)
        {
            scanf("%d", &a[i]);
            if (a[i] >= a[i-1])
                ans += (__int64)(a[i] - a[i-1]);
            else
                ans += (n-a[i-1]+a[i]);
        }
        printf("%I64d\n", ans);
    }
    return 0;
}


转载于:https://www.cnblogs.com/xindoo/p/3595048.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值