ZOJ1745 解题报告

来源:互联网 发布:mean it 编辑:程序博客网 时间:2024/05/22 15:24

1745题目题意:
(1)输入起点位置 pos
(2)输入每次移动的位置 now,通过 now-pos 与上一个now-pos相比较输出不同结果,如果now == pos,输出已经找到

注意点,格式特别容易错,只在第一个输出的序列前面没有空行,其余的前面的都有空行

代码如下:

#include <iostream>#include <cmath>using namespace std;int main(){    int pos,now,temp=0,flag=0;      while(cin>>pos && pos<5280){        if(flag++)cout<<endl; //控制格式的代码,没有此行会报错PE        while(cin>>now){            if(now==pos){                cout<<"Moving from "<<temp<<" to "<<now<<": found it!"<<endl;                break;            }            else{            if(abs(now-pos)>abs(temp-pos)){                cout<<"Moving from "<<temp<<" to "<<now<<": colder."<<endl;            }            else if(abs(now-pos)<abs(temp-pos)){                cout<<"Moving from "<<temp<<" to "<<now<<": warmer." <<endl;            }            else if(abs(now-pos)==abs(temp-pos)){                cout<<"Moving from "<<temp<<" to "<<now<<": same."<<endl;            }            }               temp = now;        }        temp=0;    }    return 0;}

代码很简单,就不多做解释了,如果有不懂得小伙伴,欢迎来问或者留言

0 0
原创粉丝点击