北大acm1006

题目链接:http://poj.org/problem?id=1006

我很神经地用了一个&和一个|,跑的结果是wrong answer,我以为是因为我的输出结果不对,可能需要全部一起输出,于是就改用了result[100]这个数组来保存结果,结果变成了runtime error,一直以为测试数据只是用sample input的,在本地跑也没任何问题,就不解了,后来同学一看,发现了&和|的问题,就改了再提交,还是runtime error,后来才知道,噢,100不够,测试数据不止止是sample的数据,就再改,依旧是wrong answer,然后一组特殊的测试值 24 29 34 0 一输入,发现答案是21253了,其实应该是1,才发现逻辑有点问题。。。再回头看,哦,一开始不用result数组的时候其实只是逻辑错而已。。。。。

Source Code

Problem: 1006   User: yuanting0505
Memory: N/A   Time: N/A
Language: C++   Result: Wrong Answer
    • Source Code
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int p,e,l,d;
    int test_case=1;
    cin>>p>>e>>l>>d;
    while((p!=-1)&&(e!=-1)&&(l!=-1)&&(d!=-1))
    {
        int n=1;
        while(((l+33*n-p)%23!=0)||((l+33*n-e)%28!=0))
        {
            n++;
        }
int result=l+33*n-d;
if(result>21252)result%=21252;
cout<<"Case "<<test_case<<": the next triple peak occurs in "<<result<<" days."<<endl; test_case++; cin>>p>>e>>l>>d; } return 0; }
原文地址:https://www.cnblogs.com/yuanting0505/p/3224764.html