![ACM試題及答案_第1頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/21/62627413-1bec-4f63-94fd-c23976633e4d/62627413-1bec-4f63-94fd-c23976633e4d1.gif)
![ACM試題及答案_第2頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/21/62627413-1bec-4f63-94fd-c23976633e4d/62627413-1bec-4f63-94fd-c23976633e4d2.gif)
![ACM試題及答案_第3頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/21/62627413-1bec-4f63-94fd-c23976633e4d/62627413-1bec-4f63-94fd-c23976633e4d3.gif)
![ACM試題及答案_第4頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/21/62627413-1bec-4f63-94fd-c23976633e4d/62627413-1bec-4f63-94fd-c23976633e4d4.gif)
![ACM試題及答案_第5頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-2/21/62627413-1bec-4f63-94fd-c23976633e4d/62627413-1bec-4f63-94fd-c23976633e4d5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、中國(guó)石油大學(xué)華東ACM試題(黃色高亮為答案)問題 A: A + B Problem題目描述給定兩個(gè)整數(shù)a, b,求兩個(gè)數(shù)之和。輸入輸入僅有一行,兩個(gè)整數(shù)a, b (0<=a, b<=10).輸出輸出 a+b的值。樣例輸入1 2樣例輸出3提示Q: Where are the input and the output?A: Your program shall always read input from stdin (Standard Input) and write output to stdout (Standard Output). For example, you can u
2、se 'scanf' in C or 'cin' in C+ to read from stdin, and use 'printf' in C or 'cout' in C+ to write to stdout. You shall not output any extra data to standard output other than that required by the problem, otherwise you will get a "Wrong Answer". User program
3、s are not allowed to open and read from/write to files. You will get a "Runtime Error" or a "Wrong Answer" if you try to do so.Q: 輸入輸出需要怎么實(shí)現(xiàn)?A:你的程序必須從stdin(Standard Input標(biāo)準(zhǔn)輸入)中讀入,將輸出數(shù)據(jù)輸出到stdout(Standard Output)。例如,在C語(yǔ)言中使用scanf和printf,在C+語(yǔ)言中使用cin和cout。除了題目要求,不允許輸出額外的信息,例如“按任意鍵退出”、
4、“請(qǐng)輸入n的值:”等等。否則將會(huì)得到Wrong Answer。 請(qǐng)不要在程序結(jié)束時(shí)加上system("pause")等調(diào)試信息。 同時(shí),你的程序不允許讀取文件或輸出到文件中,否則會(huì)得到Runtime Error或Wrong Answer。#include <stdio.h>int main() int a,b; scanf("%d %d",&a,&b); printf("%dn",a+b); return 0;問題 B: A + B Problem I時(shí)間限制: 1 Sec 內(nèi)存限制: 128 MB提交:
5、2846 解決: 2191提交狀態(tài)討論版題目描述給定兩個(gè)整數(shù)a, b,求兩個(gè)數(shù)之和。輸入輸入數(shù)據(jù)有多行.每行數(shù)據(jù)中含有兩個(gè)整數(shù)a, b (0<=a, b<=109).如果對(duì)讀取輸入數(shù)據(jù)方式產(chǎn)生疑問,請(qǐng)參考HINT。輸出對(duì)每行數(shù)據(jù),輸出對(duì)應(yīng)a+b的值。樣例輸入123 50060 8070 90樣例輸出623140160提示與Problem 1000不同的是,本題的輸入數(shù)據(jù)要求以EOF作結(jié)尾。EOF即End of File,可以表示文件結(jié)尾,也可以表示標(biāo)準(zhǔn)輸入的結(jié)尾。在ACM競(jìng)賽中,評(píng)測(cè)采用標(biāo)準(zhǔn)輸入輸出。當(dāng)題目中提示“輸入以EOF為結(jié)束”,或未指明數(shù)據(jù)組數(shù)時(shí),往往無(wú)法將數(shù)據(jù)一次性讀入存
6、入數(shù)組中,經(jīng)過計(jì)算后再輸出。在這種情況下,可以采用以下方式讀取數(shù)據(jù): 下面給出本題C語(yǔ)言代碼示例。#include <stdio.h>int main() int a,b; while(scanf("%d %d",&a, &b)!=EOF) / 輸入結(jié)束時(shí),scanf函數(shù)返回值為EOF,即沒有數(shù)據(jù)輸入時(shí)則退出while循環(huán) printf("%dn",a+b); return 0;您可參考上面給出的示例程序完成本題。當(dāng)您在本機(jī)上測(cè)試時(shí),如果采用標(biāo)準(zhǔn)輸入,需要在輸入數(shù)據(jù)結(jié)束后手動(dòng)輸入EOF。在Windows下,按下Ctrl-Z,在
7、Linux下,按下Ctrl-D即可。如果采用從文件讀入(或重定向輸入輸出流到文件),則不必在文件結(jié)尾添加其他字符。但請(qǐng)注意,在提交代碼前請(qǐng)將freopen、fopen等語(yǔ)句注釋或刪除。#include <stdio.h>/EOF方法,因?yàn)樵谠诰€評(píng)判中,所有輸入都是用文件來(lái)模擬輸入的,因此EOF方法成為了一種常見方法int main() int a,b; while(scanf("%d %d",&a, &b)!=EOF) printf("%dn",a+b); return 0;問題 C: A + B Problem II時(shí)間限制
8、: 1 Sec 內(nèi)存限制: 128 MB提交: 2638 解決: 2161提交狀態(tài)討論版題目描述給定兩個(gè)整數(shù)a, b,求兩個(gè)數(shù)之和。輸入:輸入數(shù)據(jù)中的第一行是一個(gè)正整數(shù)T (0<=T<=1000).接下來(lái)有T行數(shù)據(jù)。每行數(shù)據(jù)中含有兩個(gè)整數(shù)a, b (-103<=a, b<=103). 輸出:對(duì)每行數(shù)據(jù),輸出對(duì)應(yīng)a+b的值。樣例輸入31 2100 100300 300樣例輸出3200600提示與Problem 1001不同的是,本題給定了輸入數(shù)據(jù)組數(shù)T。本題仍然需要采用循環(huán)讀入。下面給出三個(gè)示例程序。示例1:使用for循環(huán),一邊讀入一邊輸出#include <std
9、io.h>int main() int T, a, b, i; scanf("%d",&T); for(int i=0; i<T; i+) scanf("%d%d", &a, &b); printf("%dn",a+b); return 0;示例2:使用while循環(huán),一邊讀入一邊輸出#include <stdio.h>int main() int T, a, b; scanf("%d",&T); while(T-) scanf("%d%d"
10、;, &a, &b); printf("%dn",a+b); return 0;示例3:使用for循環(huán),將數(shù)據(jù)存入數(shù)組后再處理。當(dāng)T較大時(shí),不建議采取此種方法#include <stdio.h>int main() int T, a1010, b1010, i; scanf("%d",&T); for(int i=0; i<T; i+) scanf("%d%d", &ai, &bi); for(int i=0; i<T; i+) printf("%dn"
11、;,ai+bi); return 0;#include <stdio.h>/這是典型的計(jì)數(shù)法,根據(jù)給定數(shù)值決定輸入數(shù)量/方法1int main() int ls,a,b,i; scanf("%d",&ls); for (i = 0; i < ls; i+) scanf("%d %d", &a, &b); printf("%dn",a+b); return 0;/方法二int main() int ls,a,b,i; scanf("%d",&ls); while (l
12、s-)/利用整數(shù)和邏輯類型之間的對(duì)應(yīng)關(guān)系 scanf("%d %d", &a, &b); printf("%dn",a+b); return 0;問題 D: A + B Problem III題目描述給定兩個(gè)整數(shù)a, b,求兩個(gè)數(shù)之和。輸入輸入數(shù)據(jù)有多行。每行數(shù)據(jù)中含有兩個(gè)整數(shù)a, b (0<=a, b<=109).最后一行數(shù)據(jù)是0 0,標(biāo)志著輸入結(jié)束。0 0 一行本身不需要計(jì)算輸出。如果對(duì)讀取輸入數(shù)據(jù)方式產(chǎn)生疑問,請(qǐng)參考HINT。輸出對(duì)每行數(shù)據(jù),輸出對(duì)應(yīng)a+b的值。樣例輸入123 50060 8070 900 0樣例輸出62
13、3140160提示與Problem 1001相似,本題的輸入數(shù)據(jù)組數(shù)未知,但給出了0 0作為輸入的結(jié)束符。您可以據(jù)此編制程序。(提示:判斷a、b的值是否全為0)題目描述給定一些整數(shù),對(duì)他們求和。輸入輸入數(shù)據(jù)有多行。每行數(shù)據(jù)中第一個(gè)整數(shù)N (0<=N<=100),后面跟著N個(gè)整數(shù)ai (-1000<=ai<=1000)最后一行數(shù)據(jù)是0,標(biāo)志著輸入結(jié)束。0一行本身不需要計(jì)算輸出。輸出對(duì)每一行N個(gè)正整數(shù)ai求和并輸出。樣例輸入4 1 2 3 45 1 2 3 4 50樣例輸出1015#include <stdio.h>/這種輸入被稱為哨兵法,選擇一個(gè)特定的值作為結(jié)
14、束標(biāo)記,也就是一個(gè)哨兵,防止你超出范圍。在這個(gè)題目中的哨兵就是0/方法1(推薦方法)int main() int a,b; while(1) scanf("%d %d",&a, &b); if (a = 0 && b = 0) break; printf("%dn",a+b); return 0;/方法2int main() int a,b; scanf("%d %d",&a, &b);/先讀一次 while(a != 0 | b != 0) printf("%dn"
15、,a+b); scanf("%d %d",&a, &b); return 0;/方法3int main() int a,b; do scanf("%d %d",&a, &b); if (a = 0 && b = 0) break; printf("%dn",a+b); while(a != 0 | b != 0); return 0;/方法4int main() int a,b; while(scanf("%d %d",&a, &b),a != 0 |
16、 b != 0)/利用逗號(hào)表達(dá)式,逗號(hào)表達(dá)式從左向右計(jì)算,它的返回結(jié)果是最后一個(gè)表達(dá)式的結(jié)果 printf("%dn",a+b); return 0;問題 E: A + B Problem IV題目描述給定一些整數(shù),對(duì)他們求和。輸入輸入數(shù)據(jù)有多行。每行數(shù)據(jù)中第一個(gè)整數(shù)N (0<=N<=100),后面跟著N個(gè)整數(shù)ai (-1000<=ai<=1000)最后一行數(shù)據(jù)是0,標(biāo)志著輸入結(jié)束。0一行本身不需要計(jì)算輸出。輸出對(duì)每一行N個(gè)正整數(shù)ai求和并輸出。樣例輸入4 1 2 3 45 1 2 3 4 50樣例輸出1015#include <stdio.h
17、>/哨兵法和計(jì)數(shù)法的復(fù)合輸入int main() int num,sum,tmp,i; while (scanf("%d",&num),num!=0) sum = 0; while(num-) scanf("%d",&tmp); sum += tmp; printf("%dn",sum); 問題 F: A + B Problem VYour task is to calculate the sum of some integers.輸入Input contains an integer N in the firs
18、t line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.輸出For each group of input integers you should output their sum in one line, and with one line of output for each line in input.樣例輸入24 1 2 3 45 1 2 3 4 5樣例輸出1015#include <stdio.h>/計(jì)數(shù)法
19、和計(jì)數(shù)法的復(fù)合int main() int num,num2,sum,tmp,i,j; scanf("%d",&num); while(num-) scanf("%d",&num2); sum = 0; while(num2-) scanf("%d",&tmp); sum += tmp; printf("%dn",sum); return 0;問題 G: A + B Problem VI時(shí)間限制: 1 Sec 內(nèi)存限制: 128 MB題目描述Your task is to calculate
20、 the sum of some integers.輸入Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.輸出For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.樣例輸入4 1
21、2 3 45 1 2 3 4 5#include <stdio.h>/EOF方法和計(jì)數(shù)法的復(fù)合int main() int num,sum,tmp,i; while(scanf("%d",&num)!=EOF) sum = 0; for (i = 0; i < num; i+) scanf("%d",&tmp); sum += tmp; printf("%dn",sum); return 0;問題 H: A + B Problem VII題目描述Your task is to Calculate a
22、+ b.輸入The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.輸出For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.樣例輸入1 510 20樣例輸出630#include <stdio.h>int main() int a,b; while
23、(scanf("%d %d",&a,&b)!=EOF) printf("%dnn",a + b);/注意,題目中要求每行輸出后面加一個(gè)空行 return 0;問題 I: A + B Problem VIII題目描述Your task is to calculate the sum of some integers.輸入Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and t
24、hen M integers follow in the same line.輸出For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.樣例輸入34 1 2 3 45 1 2 3 4 53 1 2 3樣例輸出10156#include <stdio.h>/計(jì)數(shù)法和計(jì)數(shù)法的復(fù)合int main() int num,num2,sum,tmp,i,j; scanf("
25、;%d",&num); for (i = 0; i < num; i+) scanf("%d",&num2); sum = 0; for (j = 0; j < num2; j+) scanf("%d",&tmp); sum += tmp; printf("%dnn",sum); return 0;China University of Petroleum 主頁(yè) 討論版 問題 狀態(tài) 排名 9 競(jìng)賽&作業(yè) 名校聯(lián)賽 常見問答 劃詞翻譯 開啟修改帳號(hào) 1503030406 (0) Re
26、cent 注銷 “端點(diǎn)杯”2015年中國(guó)石油大學(xué)新生賽敬請(qǐng)關(guān)注!China University of Petroleum Online Judge FAQQ:這個(gè)在線裁判系統(tǒng)使用什么樣的編譯器和編譯選項(xiàng)?A:系統(tǒng)運(yùn)行于Debian/Ubuntu Linux. 使用GNU GCC/G+ 作為C/C+編譯器, Free Pascal 作為pascal 編譯器 ,用 sun-java-jdk1.6 編譯 Java. 對(duì)應(yīng)的編譯選項(xiàng)如下:C:gcc Main.c -o Main -fno-asm -O2 -Wall -lm -static -std=c99 -DONLINE_JUDGEC+:g+ M
27、ain.cc -o Main -fno-asm -O2 -Wall -lm -static -DONLINE_JUDGEPascal:fpc Main.pas -oMain -O1 -Co -Cr -Ct -CiJava:javac -J-Xms32m -J-Xmx256m Main.java *Java has 2 more seconds and 512M more memory when running and judging.編譯器版本為(系統(tǒng)可能升級(jí)編譯器版本,這里直供參考):gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5glibc 2.3.6Fr
28、ee Pascal Compiler version 2.4.0-2 2010/03/06 for i386java version "1.6.0_22"Q:程序怎樣取得輸入、進(jìn)行輸出?A:你的程序應(yīng)該從標(biāo)準(zhǔn)輸入 stdin('Standard Input')獲取輸出 并將結(jié)果輸出到標(biāo)準(zhǔn)輸出 stdout('Standard Output').例如,在C語(yǔ)言可以使用 'scanf' ,在C+可以使用'cin' 進(jìn)行輸入;在C使用 'printf' ,在C+使用'cout'進(jìn)行輸出
29、.用戶程序不允許直接讀寫文件, 如果這樣做可能會(huì)判為運(yùn)行時(shí)錯(cuò)誤 "Runtime Error"。下面是 1000題的參考答案C+:#include <iostream>using namespace std;int main() int a,b; while(cin >> a >> b) cout << a+b << endl;return 0;C:#include <stdio.h>int main() int a,b; while(scanf("%d %d",&a, &b) != EOF) printf("%dn",a+b);return 0;PASCAL:program p1001(Input,Output); var a,b:Integer; begin while not eof(Input) do begin Readln(a,b); Writeln(a+b); end; end.Java:import java.util.*;public class Mainpu
溫馨提示
- 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030全球活塞連桿套件行業(yè)調(diào)研及趨勢(shì)分析報(bào)告
- 家電維修合同協(xié)議書正規(guī)范本
- 垃圾桶項(xiàng)目采購(gòu)合同
- 出租車租賃合同模板
- 2025居間合同協(xié)議書范本
- 產(chǎn)品全國(guó)總代理合同范本年
- 宣傳欄制作安裝合同書
- 委托合同范文年
- 2025年中圖版八年級(jí)歷史上冊(cè)階段測(cè)試試卷
- 2024年高考政治(安徽卷)真題詳細(xì)解讀及評(píng)析
- 數(shù)字經(jīng)濟(jì)學(xué)導(dǎo)論-全套課件
- 動(dòng)物檢疫技術(shù)-動(dòng)物檢疫的對(duì)象(動(dòng)物防疫與檢疫技術(shù))
- 中考記敘文閱讀
- 《計(jì)算機(jī)應(yīng)用基礎(chǔ)》-Excel-考試復(fù)習(xí)題庫(kù)(含答案)
- 產(chǎn)科溝通模板
- 2023-2024學(xué)年四川省成都市小學(xué)數(shù)學(xué)一年級(jí)下冊(cè)期末提升試題
- GB/T 7462-1994表面活性劑發(fā)泡力的測(cè)定改進(jìn)Ross-Miles法
- GB/T 2934-2007聯(lián)運(yùn)通用平托盤主要尺寸及公差
- GB/T 21709.13-2013針灸技術(shù)操作規(guī)范第13部分:芒針
- 2022年青島職業(yè)技術(shù)學(xué)院?jiǎn)握姓Z(yǔ)文考試試題及答案解析
- 急診科進(jìn)修匯報(bào)課件
評(píng)論
0/150
提交評(píng)論