acm教程 java版_[轉]ACM之java速成

這里指的java速成,只限于java語法,包括輸入輸出,運算處理,字符串和高精度的處理,進制之間的轉換等,能解決OJ上的一些高精度題目。

1. 輸入:

格式為:Scanner cin = new Scanner

(new

BufferedInputStream(System.in));

例程:

import java.io.*;

import

java.math.*;

import

java.util.*;

import java.text.*;

public class Main

{

public

static void main(String[] args)

{

Scanner cin = new Scanner

(new

BufferedInputStream(System.in));

int a; double b; BigInteger

c;

String st;

a = cin.nextInt(); b = cin.nextDouble(); c

=

cin.nextBigInteger(); d = cin.nextLine(); //

每種類型都有相應的輸入函數.

}

}

2. 輸出

函數:System.out.print();

System.out.println();

System.out.printf();

System.out.print(); // cout

<<

…;

System.out.println(); // cout << …

<<

endl;

System.out.printf(); // 與C中的printf用法類似.

例程:

import java.io.*;

import

java.math.*;

import

java.util.*;

import java.text.*;

public class Main

{

public

static void main(String[] args)

{

Scanner cin = new Scanner

(new

BufferedInputStream(System.in));

int a; double b;

a

=

12345; b = 1.234567;

System.out.println(a + ” ” +

b);

System.out.printf(“%d %10.5f\n”, a, b); //

輸入b為字寬為10,右對齊,保留小數點后5位,四舍五入.

}

}

規格化的輸出:

函數:

//

這里0指一位數字,#指除0以外的數字(如果是0,則不顯示),四舍五入.

DecimalFormat fd = new

DecimalFormat(“#.00#”);

DecimalFormat gd =

new

DecimalFormat(“0.000″);

System.out.println(“x =” +

fd.format(x));

System.out.println(“x =” +

gd.format(x));

3.

字符串處理

java中字符串String是不可以修改的,要修改只能轉換為字符數組.

例程:

import java.io.*;

import

java.math.*;

import

java.util.*;

import java.text.*;

public class Main

{

public

static void main(String[] args)

{

int i;

Scanner

cin = new Scanner (new

BufferedInputStream(System.in));

String st =

“abcdefg”;

System.out.println(st.charAt(0)); //

st.charAt(i)就相當于st.

char []

ch;

ch = st.toCharArray(); //

字符串轉換為字符數組.

for (i = 0; i

< ch.length; i++) ch += 1;

System.out.println(ch); //

輸入為“bcdefgh”.

if (st.startsWith(“a”)) //

如果字符串以’0′開頭.

{

st = st.substring(1); //

則從第1位開始copy(開頭為第0位).

}

}

}

4.

高精度

BigInteger和BigDecimal可以說是acmer選擇java的首要原因。

函數:add,

subtract,

divide,

mod,

compareTo等,其中加減乘除模都要求是BigInteger(BigDecimal)和BigInteger(BigDecimal)之間的運算,所以需要把int(double)類型轉換為BigInteger(BigDecimal),用函數BigInteger.valueOf().

例程:

import java.io.*;

import

java.math.*;

import

java.util.*;

import java.text.*;

public class Main

{

public

static void main(String[] args)

{

Scanner cin = new Scanner

(new

BufferedInputStream(System.in));

int a = 123, b = 456, c

=

7890;

BigInteger x, y, z, ans;

x =

BigInteger.valueOf(a);

y = BigInteger.valueOf(b); z =

BigInteger.valueOf(c);

ans =

x.add(y);

System.out.println(ans);

ans =

z.divide(y);

System.out.println(ans);

ans =

x.mod(z);

System.out.println(ans);

if (ans.compareTo(x) ==

0)

System.out.println(“1″);

}

}

5.

進制轉換

java很強大的一個功能。

函數:

String st = Integer.toString(num,

base); //

把num當做10進制的數轉成base進制的st(base <= 35).

int num =

Integer.parseInt(st, base);

//

把st當做base進制,轉成10進制的int(parseInt有兩個參數,第一個為要轉的字符串,第二個為說明是什么進制).

BigInter

m = new BigInteger(st, base); //

st是字符串,base是st的進制.

6.

排序

函數:Arrays.sort();至于怎么排序結構體,像C++里寫個cmp的方法,在java還不太清楚,希望有人指點下~~

例程:

import java.io.*;

import

java.math.*;

import

java.util.*;

import java.text.*;

public class Main

{

public

static void main(String[] args)

{

Scanner cin = new Scanner

(new

BufferedInputStream(System.in));

int n =

cin.nextInt();

int a[] = new int [n];

for (int i = 0; i

< n; i++) a =

cin.nextInt();

Arrays.sort(a);

for (int i

= 0; i <

n; i++) System.out.print(a + ” “);

}

}

7. POJ高精度題目匯總:

POJ 1131 1205 1220

1405 1503 1604 1894 2084 2305

2325 2389 2413 3101

3199

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/279099.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/279099.shtml
英文地址,請注明出處:http://en.pswp.cn/news/279099.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

配置SSH非管理員用戶登錄

以root身份登進系統后&#xff0c;增加一個非root帳戶&#xff0c;名稱為:systemadmin&#xff0c;密碼按您的需求設置一個即可。接下來我們要禁止root直接登陸。 [rootmail ~]# useradd systemadmin [rootmail ~]# passwd systemadmin [rootmail ~]# vim /etc/ssh/sshd_conf…

火狐查cookie_Firefox 65默認會阻止跟蹤Cookie

火狐查cookieMozilla today released Firefox 63, which includes an experimental option to block third-party tracking cookies, protecting against cross-site tracking. You can test this out today, but Mozilla wants to enable it for everyone by default in Firef…

chromebook刷機_如何將iTunes音樂移至Chromebook

chromebook刷機If you switch between platforms a lot, you know it’s a hassle to move your stuff around. Fortunately, music files don’t have any sort of DRM tying them to a specific platform the way that movies do, so you can copy and paste your library ar…

機房管理系列之殺毒服務器維護

對于企業安全管理方面&#xff0c;“防患于未然”&#xff0c;事前的預防遠遠大于事故處理&#xff0c;在企業內部保障機房服務器安全運行尤為重要&#xff0c;如何確保企業的安全&#xff1f;我們接下來講的就是對Symantec殺毒服務器的管理。首先是掃描策略的應用。什么時間升…

php v9 上傳_phpcms v9 表單添加文件上傳字段

phpcms v9 表單添加文件上傳字段1.打開目錄 ./phpcms/modules/content/fields/ ;把 文件夾downfile&#xff0c;拷貝到目錄./phpcms/modules/formguide/fields/里面。2.打開文件 ./phpcms/modules/formguide/fields/fields.inc.php ,在數組$fields添加值 ‘downfile’>’文件…

nowcoder OI 周賽 最后的晚餐(dinner) 解題報告

最后的晚餐&#xff08;dinner&#xff09; 鏈接&#xff1a; https://www.nowcoder.com/acm/contest/219/B 來源&#xff1a;牛客網 題目描述 \(\tt{**YZ}\)&#xff08;已被和諧&#xff09;的食堂實在是太擠辣&#xff01;所以\(\tt{Apojacsleam}\)現在想邀請他的一些好友去…

阿里巴巴Java開發手冊終極版

2019獨角獸企業重金招聘Python工程師標準>>> 一、編程規約&#xff1a; (一)命名風格 1. 【強制】 代碼中的命名均不能以下劃線或美元符號開始&#xff0c;也不能以下劃線或美元符號結束。 反例&#xff1a; _name / __name / $Object / name_ / name$ / Object$ 2.…

ios6.1.6可用微信_這是iOS 12.1的新增功能,今天可用

ios6.1.6可用微信While iOS 12 is still fairly fresh, the first point release will be rolling out starting today. This brings a handful of new features, like Group Facetime, dual SIM support, camera improvements, new emoji, and more. 盡管iOS 12仍然相當新鮮&a…

Hadoop實戰項目之網站數據點擊流分析(轉載分析)

本文轉載于csdn博主‘一直不懂’ 一&#xff0c;項目業務背景 https://blog.csdn.net/shenchaohao12321/article/details/82958936 二&#xff0c;整體技術流程及架構 https://blog.csdn.net/shenchaohao12321/article/details/82959255 三&#xff0c;數據采集 https://blog.c…

php rewrite url_PHP實現url重寫和.htaccess

.htaccess是一個完整的文件名(只有后綴)&#xff0c;它是用于Apache服務器下的配置文件&#xff0c;當.htaccess文件放在某一文件夾下&#xff0c;它僅對該文件夾下的文件和文件夾有效。通過.htaccess文件&#xff0c;可以配置服務器實現很多功能&#xff0c;比如錯誤定位&…

esp32 cam工作電流_我如何在家工作:Cam的生產力之痛

esp32 cam工作電流Telecommuting is becoming more and more common these days, with many tech writers (myself included) working from home on a full-time basis. I get asked about how I work fairly often, so here’s the skinny. 如今&#xff0c;遠程辦公變得越來越…

PL/SQL Developer結合oracle精簡客戶端配置說明

oracle 11g精簡版客戶端配置 ORACLE 一般情況下都會部署在服務器上&#xff0c;而在客戶端上需使用PL/SQL Developer 等連接工具連接服務器上的 ORACLE 。 而此時往往需要在客戶端上也安裝上百兆的 ORACLE 然后通過 ORACLE 的網絡配置向導來配置完成 PL/SQL Developer 的支持。…

NUMPY數據集練習 ----------SKLEARN類

123456<br><br># 1. 安裝scipy&#xff0c;numpy&#xff0c;sklearn包import numpyfrom sklearn.datasets import load_iris# 2. 從sklearn包自帶的數據集中讀出鳶尾花數據集dataprint(data.data)123# 3.查看data類型&#xff0c;包含哪些數據data load_iris()pr…

java 偽異步 netty,大話netty系列之--偽異步BIO

生意規模擴大話說&#xff0c;老王和大明的生意越來越好&#xff0c;這就需要兩個人增強業務往來&#xff0c;由于天南地北&#xff0c;兩個人只能每次運輸都需要雇一個人去運貨(new 一個線程)&#xff0c;一個月下來&#xff0c;兩人一算&#xff0c;人力成本太大了&#xff0…

如何使用Windows搜索在任何文件中搜索文本

Many of us rely on Windows Search to find files and launch programs, but searching for text within files is limited to specific file types by default. Here’s how you can expand your search to include other text-based files. 我們中的許多人都依賴Windows搜索…

php算法求出兔子數列,PHP算法:斐波那契數列的N種算法

前言前段時間&#xff0c;遇到優化計算斐波那契數列的常規遞歸方法&#xff0c;但是一時間并沒有及時想到很好的方法&#xff0c;所以后面查找了相關資料&#xff0c;總結了多種計算解法&#xff0c;所以分享出來&#xff0c;和大家一起交流學習。斐波那契數是什么斐波那契數列…

.net core MongoDB 初試

是這樣的&#xff0c;我們有一個場景&#xff0c;另一個服務器是寫到MongoDB里面&#xff0c;我們的MVC頁面要展示&#xff0c;需要分頁展示 自己寫了一個DAL public class MongoConnect{public string ConnectString { get; set; }}public class MongoBaseDAL<TEntity>{…

Linux文件和目錄權限:chmod、更改所有者和所屬組:chown,umask命令,隱藏權限:lsattr/chattr...

文件和目錄權限chmod&#xff1a; 我們使用ls -l可以看到文件的詳細信息&#xff0c;也知道第一列的第一個符號(字母)表示文件的類型&#xff0c;在表示文件的類型符號的后面的九個符號則表示的是文件的權限&#xff0c;這些權限和文件的所有者和所屬組都有關系&#xff1a; 文…

【技術累積】【點】【java】【27】@JSONField

JSONField 該注解隸屬于阿里fastjson&#xff0c;方便fastjson處理對象時的一些操作 源碼 Retention(RetentionPolicy.RUNTIME) Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) public interface JSONField {/*** config encode/decode ordinal* s…

百度php editor圖片上傳到其他盤,百度編輯器Editor圖片獨立上傳

將百度編輯器中的圖片獨立出來上傳&#xff1a;html:代碼var myEditorImage,d,myEditorImage new UE.ui.Editor();myEditorImage.render(uploadid);myEditorImage.ready(function(){myEditorImage.setDisabled();myEditorImage.hide();//隱藏UE框體myEditorImage.addListener(…