Link Exchange
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
จากโจทย์ในเว็บ http://www.sourcecode.in.th/wbread.php?no=3502เข้ามาสอบถาม ผมว่างๆจึงได้ลองเขียนเล่นๆดู โดยมีโจทย์ดังนี้รับข้อมูลเข้า textfile เป็น0 0 1 0 2 0 1 0 2 0 1 0 00 1 2 3 4 5 6 7 8 9 00 1 0 0 2 1 0 0 0 0 0 0 2ผมอยากให้มันอ่านtextfileเป็น6115-------------------------------------**จุดผิดของโจทย์คือ "0 1 0 0 2 1 0 0 0 0 0 0 2" >>10 ไม่ใช่ 5 ตามที่โจทย์เฉลย
package warp; /** * @Auther: Mr.Suppakit Thongdee * @Website: www.sourcecode.in.th */ public class Warp { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int iCount = 0; int iTemp = 0; String strData = "0 0 1 0 2 0 1 0 2 0 1 0 0"; //String strData = "0 1 2 3 4 5 6 7 8 9 0"; //String strData = "0 1 0 0 2 1 0 0 0 0 0 0 2"; System.out.println("Input :" + strData); String[] arrData = strData.split(" "); for (int i = 0; i < arrData.length; i++) { System.out.println(">>" + arrData[i]); iCount = iCount + 1; if (!arrData[i].equalsIgnoreCase("0")) { iTemp = 0; for (int j = i + 1; j < arrData.length; j++) { if (arrData[i].equalsIgnoreCase(arrData[j])) { iTemp = j; } } if (iTemp > 0) { i = iTemp - 1; } } } System.out.println("Output = " + iCount); } }
Home - Article - Tutorial - Sourcecode - Dev Handbook - Search - WebBoard - Links - About Us