1:A+B Problem

來源:互聯網
上載者:User

標籤:blog   http   java   os   strong   io   

總時間限制: 
1000ms 
記憶體限制: 
65536kB
描述

Calculate a + b

輸入
Two integer a,,b (0 ≤ a,b ≤ 10)
輸出
Output 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 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 shall not output any extra data 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++:
[cpp] view plaincopyprint? 
  1. #include <iostream>  
  2. using namespace std;  
  3. int  main()  
  4. {  
  5.     int a,b;  
  6.     cin >> a >> b;  
  7.     cout << a+b << endl;  
  8.     return 0;  
  9. }  

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:
[cpp] view plaincopyprint? 
  1. #include <stdio.h>  
  2.   
  3. int main()  
  4. {  
  5.     int a,b;  
  6.     scanf("%d %d",&a, &b);  
  7.     printf("%d\n",a+b);  
  8.     return 0;  
  9. }  

Here is a sample solution for problem 1000 using PASCAL:
[plain] view plaincopyprint? 
  1. program p1000(Input,Output);   
  2. var   
  3.   a,b:Integer;   
  4. begin   
  5.    Readln(a,b);   
  6.    Writeln(a+b);   
  7. end.  

Here is a sample solution for problem 1000 using JAVA:

Now java compiler is jdk 1.5, next is program for 1000
[java] view plaincopyprint? 
  1. import java.io.*;  
  2. import java.util.*;  
  3. public class Main  
  4. {  
  5.             public static void main(String args[]) throws Exception  
  6.             {  
  7.                     Scanner cin=new Scanner(System.in);  
  8.                     int a=cin.nextInt(),b=cin.nextInt();  
  9.                     System.out.println(a+b);  
  10.             }  
  11. }  

Old program for jdk 1.4
[java] view plaincopyprint? 
  1. import java.io.*;  
  2. import java.util.*;  
  3.   
  4. public class Main  
  5. {  
  6.     public static void main (String args[]) throws Exception  
  7.     {  
  8.         BufferedReader stdin =   
  9.             new BufferedReader(  
  10.                 new InputStreamReader(System.in));  
  11.   
  12.         String line = stdin.readLine();  
  13.         StringTokenizer st = new StringTokenizer(line);  
  14.         int a = Integer.parseInt(st.nextToken());  
  15.         int b = Integer.parseInt(st.nextToken());  
  16.         System.out.println(a+b);  
  17.     }  
  18. }  
原始碼:


  

 
[java] view plaincopyprint? 
  1. <pre name="code" class="cpp">int main(void)  
  2. {  
  3.     int a, b;  
  4.     scanf("%d%d", &a, &b);  
  5.     printf("%d", a+b);  
  6.     return 0;  
  7. }  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.