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 line.
Sample Input
1 1
Sample Output
2
問題簡述:
第一行輸入兩個整型數字並以空格分開,第二行輸出A+B的結果,並且要可以輸入多組資料。
問題分析:
為了實現可以輸入多組資料即程式不能結束,考慮利用while搭配 EOF 使用。
Virtual Judge通過的程式碼如下:
#include <iostream>
using namespace std;
int main()
{
int a, b;
while (scanf_s("%d %d", &a, &b) != EOF)//能夠讓while 下面的語句一直執行不會讓程式結束
{
printf("%d\n", a + b);
}
return 0;
}
相關推薦
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
ACM第一期練習題第一小題:String Task
click here to have a try Time limit 2000ms Memory limit 262144KB 題目原題: Petya started to attend programming lessons. On the first lesson his task
ACM第一期練習題第二小題:George and Accommodation
George and Accommodation Time limit 1000ms; Memory limit 262144KB; Problem Description: George has recently entered the BSUCP (Berland State
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第一期練習題第七小題:計算球體積
click here to have a try 問題要求: Time limit 1000ms Memory 32768KB 問題資料: 根據輸入的半徑值,計算球的體積。 Input 輸入資料有多組,每組佔一行,每行包括一個實數,表示球的半徑。 Output 輸出對應的球的體積
ACM第一期練習題第六小題:ASCII碼排序
click here to have a try first 問題題目: ASCII碼排序 Time limit 1000ms Memory 32768KB 題目訊息: 輸入三個字元後,按各字元的ASCII碼從小到大的順序輸出這三個字元。 Input 輸入資料有多組,每組佔一行,
ACM第一次訓練第三題
格式方面除了點問題,導致解決時間過長。。我用的方法是判斷相鄰兩個字母是否相同,如果相同則記錄,再繼續判斷,最後記錄出的值就是取走石頭的數 #include <stdio.h> int main() { int n,i; while (scanf("%d",&n)!=E
ACM第一次訓練第四題
#include <stdio.h> #include <stdlib.h> int main() { int a,b; while(scanf("%d %d",&a,&b)!=EOF) { printf("%d\n
ACM第一次訓練第六題
#include <stdio.h> #include <stdlib.h> int main() { char a[4]; char t; int=i; while (scanf("%s",a)!=EOF) { if(a[0]>a[1]) {t=a[0]; a
ACM第一次訓練第七題
#include <stdio.h> #include <stdlib.h> #define PI 3.1415927 int main() { double r; while (scanf("%lf",&r)!=EOF) printf("%.3f\n",(r
水題 第四站 HDU A + B Problem II
一道很簡單的題目讓我做得噁心無比,大數問題,不熟悉java,還是用C++寫吧。顯然需要用到字串,然後再將字串中的數字轉化為整數型別進行加法運算。去年做類似題目的時候還只知其然不知其所以然,現在明白了為什麼不能直接讀入陣列。 然而時隔一年也忘記了思路,加上當時沒有總結過,只是仿照程式碼敲
HDU1402:A * B Problem Plus——題解
|| name nbsp pro style plus string stream size http://acm.hdu.edu.cn/showproblem.php?pid=1402 給出兩個高精度正整數,求它們的積,最長的數長度不大於5e4。 FFT裸題,
廈理OJ——1002:A+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
BZOJ P1000:a+b problem
很有思維難度的一道題目 思路講不清楚,程式碼是網上抄來的 我還是太弱了 #include<algorithm> using namespace std; int a,b; int mai
ACM練習第一期第三小題:Stones on the table
Stones on the table Time limit 2000ms; Memory 262144KB Problem Description:(Stones on the Table) There are n stones on the table in a row, eac
劍指offer程式設計題(JAVA實現)——第36題:兩個連結串列的第一和公共節點
github https://github.com/JasonZhangCauc/JZOffer 劍指offer程式設計題(JAVA實現)——第36題:兩個連結串列的第一和公共節點
劍指offer程式設計題(JAVA實現)——第34題:第一次只出現一次的字元
github https://github.com/JasonZhangCauc/JZOffer 劍指offer程式設計題(JAVA實現)——第34題:第一次只出現一次的字元
LeetCode——第387題:字串的第一個唯一字元
題目: 給定一個字串,找到它的第一個不重複的字元,並返回它的索引。如果不存在,則返回 -1。 案例: s = “leetcode” 返回 0. s = “loveleetcode”, 返
劍指offer第3題:從尾到頭打印鏈表
off 輸出結果 pre col 結構 ava image stack 鏈表 方法一:采用棧來存儲,用ArrayList保存。註意題目給出的輸出結果是ArrayList import java.util.ArrayList; import java.util.Sta
leetcode第32題:最長有效括號(遇到一個奇葩的錯誤)
問題描述: 給一個只包含 '(' 和 ')' 的字串,找出最長的有效(正確關閉)括號子串的長度。 對於 "(()",最長有效括號子串為 "()" ,它的長度是 2。 另一個例子 ")()())",最長有效括號子