輸入一些整數,求出它們的最小值、最大值和平均值(保留3位小數)。 輸入保證這些數都是不超過1000的整數。
樣例輸入:
2 8 3 5 1 7 3 6
樣例輸出:
1 8 4.375
#include "stdio.h"
int main()
s += x;
if (x > max) max = x;
if (x < min) min = x;
++n;
}printf("%d %d %.3f\n", min, max, double(s) / n);
return
0;}
參考code
//**********資料統計(重定向版)**************
#define
local
#include
#define inf 1000000000
int main()
printf("%d %d %.3f\n", min, max, (double)s/n);
return
0;}
有經驗的選手往往會使用條件編譯指令並且將重要的測試語句注釋掉而非刪除。
//**********資料統計(fopen版)**************
#include #define inf 1000000000
int main()
fprintf(fout, "%d %d %.3f\n", min, max, (double)s / n);
fclose(fin);
fclose(fout);
return
0;}
如果想把fopen版的程式改成讀寫標準輸入輸出,只需賦值「fin=stdin;fout=stdout;」即可,不要呼叫fopen和fclose
演算法競賽入門經典ch3 ex4豎式問題
找出所有形如abc de 三位數乘以兩位數 的算式,使得在完整的豎式中,所有數字都屬於乙個特定的數字集合。輸入數字集合 相鄰數字之間沒有空格 輸出所有 豎式。每個豎式前應有編號,之後應有乙個空行。最後輸出解的總數。樣例輸入 樣例輸出 2357 1 775x 33 2325 2325 25575 th...
演算法競賽入門經典 習題2答案
輸入乙個不超過10 9的正整數,輸出他的位數,例如12735的位數是5.請不要使用任何數學函式,只用四則運算和迴圈語句實現 include include define uint unsigned int using namespace std int main cout i endl return...
《演算法競賽入門經典》習題及反思 2
題目 給定答案序列和使用者猜的序列,統計有多少數字對應正確 a 有多少數字在兩個序列都出現過但位置不對。輸入包括多組資料。每組輸入第一行為序列長度n,第二行是答案序列,接下來是若干猜測序列。猜測序列為0時改組資料結束。n 0時輸入結束。樣例輸入 41 3 5 5 4 3 3 5 6 5 5 1 6 ...