|
| 1 | + |
| 2 | +# Description |
| 3 | + |
| 4 | +<div class="content"><p>输入两个数字,输出它们之和</p></div> |
| 5 | + |
| 6 | +# Input |
| 7 | + |
| 8 | +<div class="content"><p>一行两个数字A,B(0<=A,B<100)</p> |
| 9 | +<p></p></div> |
| 10 | + |
| 11 | +# Output |
| 12 | + |
| 13 | +<div class="content"><p>输出这两个数字之和</p> |
| 14 | +<p></p></div> |
| 15 | + |
| 16 | +# Sample Input |
| 17 | + |
| 18 | +<div class="content"><span class="sampledata">1 2</span></div> |
| 19 | + |
| 20 | +# Sample Output |
| 21 | + |
| 22 | +<div class="content"><span class="sampledata">3</span></div> |
| 23 | + |
| 24 | +# Hint |
| 25 | + |
| 26 | +<div class="content"><p></p><p>Q: Where are the input and the output? A: Your program shall always <font color="#ff0000">read input from stdin (Standard Input) and write output to stdout (Standard Output)</font>. For example, you can use '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 <font color="#ff0000">shall not output any extra data</font> to standard output other than that required by the problem, otherwise you will get a "Wrong Answer". User programs 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. Here is a sample solution for problem 1000 using C++/G++:</p><br/> |
| 27 | +<pre><br/> |
| 28 | +#include <iostream></iostream><br/> |
| 29 | +using namespace std;<br/> |
| 30 | +int main()<br/> |
| 31 | +{<br/> |
| 32 | + int a,b;<br/> |
| 33 | + cin >> a >> b;<br/> |
| 34 | + cout << a+b << endl;<br/> |
| 35 | + return 0;<br/> |
| 36 | +}</pre><br/> |
| 37 | +<p>It's important that the return type of main() must be int when you use G++/GCC,or you may get compile error. Here is a sample solution for problem 1000 using C/GCC:</p><br/> |
| 38 | +<pre><br/> |
| 39 | +#include <stdio.h></stdio.h><br/> |
| 40 | +<br/> |
| 41 | +int main()<br/> |
| 42 | +{<br/> |
| 43 | + int a,b;<br/> |
| 44 | + scanf("%d %d",&a, &b);<br/> |
| 45 | + printf("%d\n",a+b);<br/> |
| 46 | + return 0;<br/> |
| 47 | +}</pre><br/> |
| 48 | +<p>Here is a sample solution for problem 1000 using PASCAL:</p><br/> |
| 49 | +<pre><br/> |
| 50 | +program p1000(Input,Output); <br/> |
| 51 | +var <br/> |
| 52 | + a,b:Integer; <br/> |
| 53 | +begin <br/> |
| 54 | + Readln(a,b); <br/> |
| 55 | + Writeln(a+b); <br/> |
| 56 | +end.</pre><br/> |
| 57 | +<p>Here is a sample solution for problem 1000 using JAVA: Now java compiler is jdk 1.5, next is program for 1000</p><br/> |
| 58 | +<pre><br/> |
| 59 | +import java.io.*;<br/> |
| 60 | +import java.util.*;<br/> |
| 61 | +public class Main<br/> |
| 62 | +{<br/> |
| 63 | + public static void main(String args[]) throws Exception<br/> |
| 64 | + {<br/> |
| 65 | + Scanner cin=new Scanner(System.in);<br/> |
| 66 | + int a=cin.nextInt(),b=cin.nextInt();<br/> |
| 67 | + System.out.println(a+b);<br/> |
| 68 | + }<br/> |
| 69 | +}</pre><br/> |
| 70 | +<p>Old program for jdk 1.4</p><br/> |
| 71 | +<pre><br/> |
| 72 | +import java.io.*;<br/> |
| 73 | +import java.util.*;<br/> |
| 74 | +<br/> |
| 75 | +public class Main<br/> |
| 76 | +{<br/> |
| 77 | + public static void main (String args[]) throws Exception<br/> |
| 78 | + {<br/> |
| 79 | + BufferedReader stdin = <br/> |
| 80 | + new BufferedReader(<br/> |
| 81 | + new InputStreamReader(System.in));<br/> |
| 82 | +<br/> |
| 83 | + String line = stdin.readLine();<br/> |
| 84 | + StringTokenizer st = new StringTokenizer(line);<br/> |
| 85 | + int a = Integer.parseInt(st.nextToken());<br/> |
| 86 | + int b = Integer.parseInt(st.nextToken());<br/> |
| 87 | + System.out.println(a+b);<br/> |
| 88 | + }<br/> |
| 89 | +}</pre><p></p></div> |
| 90 | + |
| 91 | +# Source |
| 92 | + |
| 93 | +<div class="content"><p><a href="problemset.php?search="></a></p></div> |
| 94 | + |
0 commit comments