HDOJ 1248 寒冰王座(找规律)

【思路】:找规律,参考的别人的,自己写的挂了。http://blog.youkuaiyun.com/appte/article/details/8227632

【AC代码】:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int T = 0;
    cin >> T;
    while (T--)
    {
        int n = 0, m = 0;
        cin >> n;
        if (n<200)
            m = n%150;
        else if (n >= 200 && n < 300)
            m = n%200;
        else if (n >= 300)
            m = n%50;
        cout << m << endl;
    }
    return 0;
}

【自己写的WA代码】:1300时候就是错的,应该是0,输出50。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int T = 0;
    cin >> T;
    while (T--)
    {
        int n = 0;
        cin >> n;
        int a = n%150, b = n%200, c = n%350;
        if (b >= 150)
            b %= 150;
        if (c >= 300)
            c %= 150;
        else if (c >= 200)
            c %= 200;
        else if (c >= 150)
            c %= 150;
        if (a < b)
        {
            if (a < c)
                cout << a << " ";
            else
                cout << c << " ";
        }
        else
        {
            if (b < c)
                cout << b << " ";
            else
                cout << c << " ";
        }
    }
    return 0;
}

方法就是错的,几乎没法改。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值