日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

算法题的输入大总结

發布時間:2023/12/13 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 算法题的输入大总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

趕緊收藏吧,小白必備知識了

本文以求和為例

多組輸入,每組輸入共一行,包括兩個整數A, B

Sample Input 1 2 12 24 400 500 Sample Output 3 36 900 import java.util.Scanner; public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while(sc.hasNext()) {System.out.println(sc.nextInt()+sc.nextInt());}} }

第一行是數據的組數N,從第二行開始是N組由兩個整數(A和B)構成的數據,A和B之間用空格隔開,每組輸入單獨占一行

Sample Input 2 1 2 10 20 Sample Output 3 30 //2 import java.util.Scanner; public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n=sc.nextInt();while(n-->0) {System.out.println(sc.nextInt()+sc.nextInt());}} }

多組數據:每組由兩個整數(A和B)構成,A和B之間用空格隔開,每組輸入單獨占一行。當輸入為"0 0"時,輸入結束。"0 0"這組數據不處理。

Sample Input 1 2 3 4 10 20 0 0 Sample Output 3 7 30 //3 import java.util.Scanner; public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while(true) {int a=sc.nextInt();int b=sc.nextInt();if(a==0 && b==0)break;System.out.println(a+b);}} }

輸入包含多個測試用例。每個測試用例包含一個正整數N,隨后是N個整數跟在同一行上。當某個測試用例以0開始,終止輸入,且該用例不處理。

Sample Input 3 1 2 4 1 23 5 1 3 5 7 9 0 Sample Output 7 23 25 //4 import java.util.Scanner; public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);while(true) {int a=sc.nextInt();if(a==0)break;int ac=0;while(a-->0)ac+=sc.nextInt();System.out.println(ac);}} }

第一行為N,下面緊跟N行數據。每行數據:開頭為M,后面緊跟M個數。

Sample Input 2 1 1 2 3 4 Sample Output 1 7 //5 import java.util.Scanner; public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n=sc.nextInt();while(n-->0) {int a=sc.nextInt();if(a==0)break;int ac=0;while(a-->0)ac+=sc.nextInt();System.out.println(ac);}} } 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的算法题的输入大总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。