全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1047
推到 Plurk!
推到 Facebook!

java程式碼轉成bc++

尚未結案
coolasahi
一般會員


發表:2
回覆:1
積分:0
註冊:2011-10-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2011-10-02 23:01:44 IP:180.177.xxx.xxx 訂閱
因對borland c++部份轉換還不熟悉 請求高手協助指導~
java程式碼如下:

import java.util.*;
public class strsorting
{
//經過轉換後想要顯示的結果如下,連續的字串組顯示為:最小-最大; 不連續的就自己一個
//GPR110068-GPR110078,GPR110129,GPR110214-GPR110230,GPR110471-GPR110539
static String converMachNo(String sMachs)
{
String [] temp = sMachs.split(",");

ArrayList forsorting = new ArrayList();

for(int i = 0; i < temp.length; i )
forsorting.add(temp[i]);

Collections.sort(forsorting);

temp = forsorting.toArray(new String[0]);

int num1, num2, count = 1;

sMachs = temp[0];
num1 = Integer.parseInt(temp[0].substring(3));

for(int i = 1; i < temp.length; i )
{
num2 = Integer.parseInt(temp[i].substring(3));

if((num2 - num1) != 1)
{
if(count!= 1)
sMachs = ("-" temp[i-1] "," temp[i]);
else
sMachs = ("," temp[i]);

count = 0;
}

num1 = num2;
count ;
}

if(count!= 1)
sMachs = ("-" temp[temp.length-1]);

return sMachs;
}

public static void main ( String args [])
{
String sTest =
"GPR110539,GPR110069,GPR110070,GPR110071,GPR110072,GPR110073,GPR110074,GPR110075,"
"GPR110076,GPR110077,GPR110078,GPR110129,GPR110214,GPR110215,GPR110216,GPR110217,"
"GPR110218,GPR110219,GPR110220,GPR110221,GPR110222,GPR110223,GPR110224,GPR110225,"
"GPR110226,GPR110227,GPR110228,GPR110229,GPR110230,GPR110471,GPR110472,GPR110473,"
"GPR110474,GPR110475,GPR110476,GPR110477,GPR110478,GPR110479,GPR110480,GPR110481,"
"GPR110482,GPR110483,GPR110484,GPR110485,GPR110486,GPR110487,GPR110488,GPR110489,"
"GPR110490,GPR110491,GPR110492,GPR110493,GPR110494,GPR110495,GPR110496,GPR110497,"
"GPR110498,GPR110499,GPR110500,GPR110501,GPR110502,GPR110503,GPR110504,GPR110505,"
"GPR110506,GPR110507,GPR110508,GPR110509,GPR110510,GPR110511,GPR110512,GPR110513,"
"GPR110514,GPR110515,GPR110516,GPR110517,GPR110518,GPR110519,GPR110520,GPR110521,"
"GPR110522,GPR110523,GPR110524,GPR110525,GPR110526,GPR110527,GPR110528,GPR110529,"
"GPR110530,GPR110531,GPR110532,GPR110533,GPR110534,GPR110535,GPR110536,GPR110537,"
"GPR110538,GPR110068,GPR110544";


String sRet= converMachNo(sTest);

System.out.println(sRet);
}

}

coolasahi
一般會員


發表:2
回覆:1
積分:0
註冊:2011-10-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2011-10-02 23:35:17 IP:180.177.xxx.xxx 訂閱
換個方式問好了:
只是想請教各位前輩
String [] temp = sMachs.split(",");
ArrayList forsorting = new ArrayList();
Collections.sort(forsorting);
temp = forsorting.toArray(new String[0]);
num1 = Integer.parseInt(temp[0].substring(3));
這幾句java的語法如何改寫成BC 讓他編譯過呢?><
系統時間:2017-12-14 14:22:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!