码迷,mamicode.com
首页 > 其他好文 > 详细

1:A+B Problem

时间:2014-07-24 10:07:23      阅读:287      评论:0      收藏:0      [点我收藏+]

标签: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++:
  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:
  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:
  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
  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
  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. }  

源代码:




  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. }  

1:A+B Problem,布布扣,bubuko.com

1:A+B Problem

标签:blog   http   java   os   strong   io   

原文地址:http://www.cnblogs.com/drfxiaoliuzi/p/3864705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!