国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

java - 求解一道C語言的算法題?求各位大神幫忙

瀏覽:184日期:2024-03-25 09:03:57

問題描述

java - 求解一道C語言的算法題?求各位大神幫忙

問題解答

回答1:

我想說不考慮算法選擇要求 這就是個 2x+b = a 求x的小學(xué)數(shù)學(xué)題,如果對算法選擇沒要求就是輸入a,b,輸出(a-b)/2 和 (a+b)/ 2.輸入的時候校驗下a,b是不是同為奇數(shù)或偶數(shù)以及數(shù)字是不是超變量類型的可用范圍,然后自己生成的case也要考慮這個問題

回答2:

import java.math.BigInteger;import java.util.*;import java.io.*; public class Main { public static void main(String[] args) {Scanner input = new Scanner(System.in); String total, more;for(int t = 0; t < 10; ++t) { total = input.nextLine(); more = input.nextLine();; BigInteger total_apples = new BigInteger(total); BigInteger excess_apples = new BigInteger(more); BigInteger ans_1 = total_apples.add(excess_apples).pide(BigInteger.valueOf(2)); BigInteger ans_2 = total_apples.subtract(excess_apples).pide(BigInteger.valueOf(2)); System.out.println(ans_1); System.out.println(ans_2); } }}回答3:

通過你提供的材料,用c++編碼如下,望指正!

/* if Natalia’s number of apples is x (x>0) apples:the number of apple extra:the number that Klaudia more tha Natalia (apples>extra>0) so x+extra+x=apples x = (apples-extra)/2*/#include <iostream>int main(int argc, char const *argv[]) { int apples,extra; //apples:the number of apple extra:the number that Klaudia more tha Natalia for (size_t i = 0; i < 10; i++) {std::cin>>apples>>extra; //inputtry{ //To determine whether the input is legal if(apples<=0 || extra<=0 || apples<extra || (apples-extra)%2!=0) throw apples; int Klaudia,Natalia; Natalia = (apples-extra)/2; //calculate Klaudia=Natalia+2; std::cout<<Klaudia<<’n’<<Natalia<<’n’; //output }catch(int e){ //ERROR std::cerr << 'ERROR! the number of applse is error.n' << ’n’;} } return 0;}

運行結(jié)果java - 求解一道C語言的算法題?求各位大神幫忙

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 商水县| 闽清县| 曲沃县| 武川县| 临城县| 于都县| 鲁山县| 霍邱县| 依安县| 迁安市| 梓潼县| 西平县| 张家港市| 盐城市| 万载县| 瑞安市| 吉木萨尔县| 从化市| 高邑县| 林西县| 金山区| 平江县| 新余市| 蒙自县| 卢龙县| 泰宁县| 桐柏县| 吉首市| 小金县| 伊宁市| 全南县| 桦川县| 重庆市| 崇左市| 应用必备| 枣庄市| 湘潭县| 张家口市| 杭锦旗| 祁连县| 沙雅县|