1. 程式人生 > >ACM1000,1001,1002: A+B問題

ACM1000,1001,1002: A+B問題

這三道題都屬於比較基礎簡單的題目,按照每道題的要求寫就可以了。

1000:

Description

Your task is to Calculate a + b.

Input

Input contains multiple test cases. Each test case consists of a pair of integers a and b ( 0 <= ab <= 20 ), separated by a space, one pair of integers per line.

Output

For each pair of input integers a

 and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1 1

Sample Output

2

程式碼如下:

#include<stdio.h>
int main()
{
	int a, b;
	while((scanf("%d%d", &a, &b)) != EOF)
	printf("%d\n", a + b);
	return 0;
}

1001:

Description

Your task is to Calculate a + b.

Input

There are multiple test cases. Each test case contains only one line. Each line consists of a pair of real number a and b(0<=a,b<=1000000), separated by a space.

Output

For each case, output the answer in one line rounded to 4 digits after the decimal point.

Sample Input

1 5
10 20
0.1 1.5

Sample Output

6.0000
30.0000
1.6000

程式碼如下:

#include<stdio.h>
int main()
{
	double a, b;
	while((scanf("%lf%lf", &a, &b)) != EOF)
	{
		printf("%.4lf\n", a + b);
	}
	return 0;
}

1002:

Description

Your task is to Calculate a + b.

Input

There are multiple test cases. Each test case contains only one line. Each line consists of a pair of integers a and b ( 1 <= ab<=1016 ) , separated by a space. Input is followed by a single line with a = 0, b = 0, which should not be processed.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1 5
10 20
10000000000000000 10000000000000000
0 0

Sample Output

6
30
20000000000000000

程式碼如下:

#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std ;
 
long long int getNum(string s){
    long long int num = 0 ;
    int flag = 1 ;
    if (s[0]=='-') 
		flag = -1 ;
    for (int i = 0 ; i < s.length() ; ++i){
            if (abs(s[i]-'4')<=5){
                num+=(s[i]-'0') ;
                num *= 10 ;
            }
    }
    return flag*(num/10) ;
}

int main(){
    string a ,b ;
    while (cin>>a>>b){
    	if(getNum(a) != 0 && getNum(b) != 0){
    		cout<< getNum(a)+getNum(b)<<endl;
		}
        
    }
	return 0;
}

如果大家有更加簡潔的程式碼,歡迎評論交流

相關推薦

ACM100010011002 A+B問題

這三道題都屬於比較基礎簡單的題目,按照每道題的要求寫就可以了。 1000: Description Your task is to Calculate a + b. Input Input contains multiple test cases. Each tes

廈理OJ——1002A+B Problem

一、題目 Description Calculate a+b Input Two integer a,b (0<=a,b<=10) Output Output a+b Sample Input 1 2 Sample Output 3 H

集合差集操作a - b 的含義為在集合a但不在b中的元素集合。

a = set(‘boy’) a Out[8]: {‘b’, ‘o’, ‘y’} b = set(‘girlb’) b Out[10]: {‘b’, ‘g’, ‘i’, ‘l’, ‘r’} c = a - b c Out[12]: {‘o’, ‘y’} 集合(set)是一

演算法題假設一列火車一共經過10個車站車站按順序為 A B C D E F G H I J 編寫一個程式自動計算剩餘的票

假設一列火車一共經過10個車站,車站按順序為 A B C D E F G H I J ,編寫一個程式,自動計算剩餘的票     要求:1 假設火車有100個座位        2.程式可以輸入購買車票的起始站與結束站        3.輸入後,程式輸出剩餘車票,       

取出一個字串中字母出現的次數。如字串"abcdekka27qoq" 輸出格式為 a(2)b(1)k(2)

package com.heima.test; import java.io.FileWriter; import java.io.IOException; import java.util.Comp

輸入資料有多組。 每組一行為兩個整數A, B。 輸入以0 0結束。

#include<stdio.h> int main() { int c[100],i,t=0,a,b; scanf("%d%d",&a,&b);

王樂平 技術部落格(熱愛『健身、書法、攝影』的IT男。 如果你想僱傭我請發郵件 <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="29454c5940474e19111f695f40590758580

PWA(Progressive Web Apps) PWA(Progressive Web Apps)是結合了 web 和 原生應用中最好功能的一種體驗,是Google推出的新技術架構。 這裡會以基礎和實戰方向,撰寫一些入門系列

不使用中間變數交換int型的 a, b兩個變數的值

(function(){ var a = 10, b = 2; a = a + b; b = a - b; a = a - b; alert(a+" "+b); })(); (function(){ var a = 10,b=2; a = a^b;

【九度】題目1001A+B for Matrices

題目描述:     This time, you are supposed to find A+B where A and B are two matrices, and then count the number of zero rows and columns. 輸入

九度——題目1001A+B for Matrices

題目描述:     This time, you are supposed to find A+B where A and B are two matrices, and then count the number of zero rows and columns. 輸入

九度考研真題 浙大 2011-1浙大1001A+B for Matrices

//題目1001:A+B for Matrices #include<iostream> #include<string.h> using namespace std; int main() {int M,N;int a1[11][11],a2[11

九度oj 題目1001A+B for Matrices 【ZJU2011考研機試題1】

題目1001:A+B for Matrices 時間限制:1 秒 記憶體限制:32 兆 特殊判題:否 提交:11539 解決:4694 題目描述:     This time, you are supposed to find A+B where

HDU1402A * B Problem Plus——題解

|| name nbsp pro style plus string stream size http://acm.hdu.edu.cn/showproblem.php?pid=1402 給出兩個高精度正整數,求它們的積,最長的數長度不大於5e4。 FFT裸題,

高精度基礎3a*b問題1

專題連結:高精度題表   題目大意: 1、給出一個大整數a,一個整數型別b,求a*b; 2、保證 0<b<=10000000; ==============================================================

高精度基礎2a-b問題

專題連結:高精度題表   題目傳送門 題目大意: 1、給出兩個大整數a,b,求a=b; 2、保證 a>b; ==================================================================== 詳細

SICAU-OJ A|B

A|B 題意: 給出一個整數n(1<=n<=10100),求Σd(d滿足d可以整除n),同時保證不存在x^2有x^2可以整除n。 另外,n的質因子滿足小於等於1000。   題解: 這題是我第一道用python做的題...畢竟大數C寫起來還是挺麻煩的。 根據唯一分解定理我們

PAT乙級題目練習A+B和C

//給定區間[-2的31次方, 2的31次方]內的3個整數A、B和C,請判斷A+B是否大於C。 #include <iostream> using namespace std; int main() {     int m,i=1;     long int a,

ACM第一期練習題第八小題A + B Problem Too

click here to have a try first 題目要求: Time limit : 1000 ms Memory : 32768 KB 題目原題: This problem is also a A + B problem,but it has a little dif

ACM第一期練習第四小題A + B Problem

A+B Problem Calculate A + B. Input Each line will contain two integers A and B. Process to end of file. Output For each case, output A + B in one

Home12月2日a-b

Description Now, Give you two intgers A and B , Please calculate the value of A minus B.Attation: A、Band A−B are all non-negative numbers. Inp