作者jolinsens (cherry花)
看板C_and_CPP
標題[問題] java程式碼轉c++
時間Sun Oct 2 22:54:03 2011
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
borland c++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
java中的程式碼想轉成c++
但部份語法不熟,請求協助
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
import java.util.*;
public class strsorting{
String converMachNo(String sMachs)
{ String [] temp = sMachs.split(",");
ArrayList<String> forsorting = new ArrayList<String>();
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; }
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 180.177.74.146
推 ericinttu:你C++熟嗎? 10/02 22:58
→ jolinsens:還OK 10/02 23:09
→ uranusjr:你有想法嗎, 整段都看不懂的話去 Java 板比較有意義 10/02 23:21