zoukankan      html  css  js  c++  java
  • 1:A+B Problem

    总时间限制: 
    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 ",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. }  
    转载本Blog文章请注明出处,否则,本作者保留追究其法律责任的权利。 本人转载别人或者copy别人的博客内容的部分,会尽量附上原文出处,仅供学习交流之用,如有侵权,联系立删。
  • 相关阅读:
    poj 2100 尺取法 一个数字拆成连续数字平方和
    poj 1011 dfs+剪枝
    CF-242-C bfs+stl
    hdu 1297 递推
    poj 2104 划分树模板
    poj 3842 全排列+筛素数+暴力
    hdu 1421 经典dp
    hdu 1069 最长上升子序列变形
    hdu 3496 二维费用的01背包
    nyoj 16 最长上升子序列变形
  • 原文地址:https://www.cnblogs.com/drfxiaoliuzi/p/3864705.html
Copyright © 2011-2022 走看看