• zoj 1763 A Simple Question of Chemistry


    A Simple Question of Chemistry

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    Your chemistry lab instructor is a very enthusiastic graduate student who clearly has forgotten what their undergraduate Chemistry 101 lab experience was like. Your instructor has come up with the brilliant idea that you will monitor the temperature of your mixture every minute for the entire lab. You will then plot the rate of change for the entire duration of the lab.

    Being a promising computer scientist, you know you can automate part of this procedure, so you are writing a program you can run on your laptop during chemistry labs. (Laptops are only occasionally dissolved by the chemicals used in such labs.) You will write a program that will let you enter in each temperature as you observe it. The program will then calculate the difference between this temperature and the previous one, and print out the difference. Then you can feed this input into a simple graphing program and finish your plot before you leave the chemistry lab.


    Input

    The input is a series of temperatures, one per line, ranging from -10 to 200. The temperatures may be specified up to two decimal places. After the final observation, the number 999 will indicate the end of the input data stream. All data sets will have at least two temperature observations.


    Output

    Your program should output a series of differences between each temperature and the previous temperature. There is one fewer difference observed than the number of temperature observations (output nothing for the first temperature). Differences are always output to two decimal points, with no leading zeroes (except for the ones place for a number less than 1, such as 0.01) or spaces.

    After the final output, print a line with "End of Output"


    Sample Input

    10.0
    12.05
    30.25
    20
    999


    Sample Output

    2.05
    18.20
    -10.25
    End of Output

     分析:我只要前一个数,和当前的数就行了,就要想办法循环起来。不用容器存起来,当然用容器全部存起来在做也可以

     1 #include <iostream>
     2 using namespace std;
     3 int main(){
     4     cout.precision(2);
     5     double pre, cur;
     6     cin >> pre;
     7     if(pre == 999){
     8         cout << "End of Output" << endl;
     9         return 0;
    10     }
    11     while(cin >> cur){
    12         if(cur == 999){
    13             cout << "End of Output" << endl;
    14             break;
    15         }
    16         cout << fixed << (cur - pre) << endl;
    17         pre = cur;
    18     }
    19     //system("pause");
    20     return 0;
    21 }
  • 相关阅读:
    akka并发编程练习
    使用selenium和chromedriver组合爬虫时,如果爬取的页面数量巨多,会出现占用内存逐渐增大知道程序崩溃的情况
    网易2017秋招编程题集合_以下代码全部来自牛客网
    牛客网_运行问题
    json和xml之间转换的好文
    Eclipse 启动时闪退问题解决方案
    关于opencv的文件配置详细内容
    第一个opencv声称图片_以及遇到的问题集锦
    好文收藏_关于find_first_not_of函数
    好文收藏readtxt_cpp
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6523130.html
Copyright © 2020-2023  润新知