| Thành viên | Trả lời |
aspnet
 Lập trình không biên giới 608 bài
| 25-6-2019 11:18:4 Đọc file trong thư mục raw
========= private String readTextFromRaw(InputStream inputStream) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
String myText = ""; int in; try { in = inputStream.read(); while (in != -1) { byteArrayOutputStream.write(in); in = inputStream.read(); } inputStream.close();
myText = byteArrayOutputStream.toString(); } catch (IOException e) { e.printStackTrace(); }
return myText; } --- Cây sẽ cho lộc và cây sẽ cho hoa ...
|
aspnet
 Lập trình không biên giới 608 bài
| 25-6-2019 11:19:24 Thuật toán tìm đường ======= package com.example.ungdung;
public class FWPoint { int _x = 0; int _y = 0;
public FWPoint(int x, int y) { _x = x; _y = y; }
public int get_x(){return _x;} public void set_x(int val){_x = val;}
public int get_y(){return _y;} public void set_y(int val){_y = val;} }
============ package com.example.ungdung;
import java.util.*;
public class Street { private String _from = ""; private String _to = ""; private int _distan = 0;
public Street(String from_point, String to_point, int distance) { _from = from_point; _to = to_point; _distan = distance; }
public String get_from() { return this._from; } public void set_from(String value) { this._from = value; }
public String get_to() { return this._to; } public void set_to(String value) { this._to = value; }
public int get_distan() { return this._distan; } public void set_distan(int value) { this._distan = value; } }
=========== package com.example.ungdung;
import android.os.Build; import android.support.annotation.RequiresApi;
import java.util.*; import java.lang.*;
public class Shortway { private int FindStreet(ArrayList dt, Hashtable points) { int st = -1; int min = 10000;
Enumeration<String> enumeration = points.keys();
while (enumeration.hasMoreElements()) { String key = enumeration.nextElement(); Street pnt = (Street) points.get(key);
for (int i = 0; i < dt.size(); i++) { String from = ((Street) dt.get(i)).get_from(); if (from.equals(key)) { int total = pnt.get_distan() + ((Street) dt.get(i)).get_distan(); if (total < min) { String to_point = ((Street) dt.get(i)).get_to(); if (!points.containsKey(to_point)) // da them vao danh sach cac diem den { min = total; st = i; } } } } }
return st; }
private void FindRoutes(Hashtable points, String p_name, ArrayList routes) { if (points.containsKey(p_name)) { Street pnt = (Street) points.get(p_name); routes.add(pnt);
FindRoutes(points, pnt.get_from(), routes); } }
public ArrayList Findway(ArrayList dt, String start_point, String end_point) { Hashtable<String, Street> points = new Hashtable(); points.put(start_point, new Street("#", start_point, 0));
for (int i = 0; i < 200; i++) { int st = FindStreet(dt, points);
if (st > -1) { Street way = (Street) dt.get(st); String from_pt = way.get_from(); Street pnt = (Street) points.get(from_pt);
Street next_point = new Street(way.get_from(), way.get_to(), pnt.get_distan() + way.get_distan()); String pnt_name = way.get_to(); points.put(pnt_name, next_point);
if (pnt_name == end_point) break; } }
ArrayList routes = new ArrayList(); FindRoutes(points, end_point, routes);
return routes; }
private int getDistance(String p1, String p2, Hashtable points) { FWPoint pn1 = (FWPoint) points.get(p1.trim()); FWPoint pn2 = (FWPoint) points.get(p2.trim());
int abs_x = Math.abs(pn1.get_x() - pn2.get_x()); int abs_y = Math.abs(pn1.get_y() - pn2.get_y());
if (abs_x > abs_y) return abs_x; return abs_y; }
private String _nodes = ""; private String _nodemap = "";
public void set_nodemap(String _nodemap) { this._nodemap = _nodemap; }
public void set_nodes(String _nodes) { this._nodes = _nodes; }
public ArrayList Loadmap() { Hashtable<String, FWPoint> points = new Hashtable();
String nd[] = _nodes.split("\\r?\\n"); for (int i = 0; i < nd.length; i++) { nd = nd.trim(); if (nd.length() > 0) { String ss[] = nd.split(","); FWPoint pn = new FWPoint(Integer.parseInt(ss[1]), Integer.parseInt(ss[2])); points.put(ss[0], pn); } }
String str[] = _nodemap.split("\\r?\\n");
ArrayList routes = new ArrayList(); for (int i = 0; i < str.length; i++) { str = str.trim();
if (str.length() > 0) { String[] ss = str.split(","); Street way = new Street(ss[0].trim(), ss[1].trim(), getDistance(ss[0], ss[1], points)); routes.add(way); } }
return routes; }
public String showTheRoutes(ArrayList routes) { String txt = ""; for (int i = routes.size()-1; i >= 0; i--) { Street pnt = (Street)routes.get(i); txt += pnt.get_from() + "-" + pnt.get_to() + " = " + pnt.get_distan() + "\n"; } return txt; } }
========== Shortway al = new Shortway();
InputStream inputStream = getResources().openRawResource(R.raw.nodemap); String myText = readTextFromRaw(inputStream); al.set_nodemap(myText);
InputStream inputStream2 = getResources().openRawResource(R.raw.nodes); String s_nodes = readTextFromRaw(inputStream2); al.set_nodes(s_nodes);
ArrayList dt = al.Loadmap(); ArrayList routes = al.Findway(dt, "100", "609"); String txt = al.showTheRoutes(routes);
wlc.setText(txt); --- Cây sẽ cho lộc và cây sẽ cho hoa ...
|
aspnet
 Lập trình không biên giới 608 bài
| 28-6-2019 16:33:57 "Client does not support authentication protocol requested by server; consider upgrading MySQL client"
Sequilize + MySQL + Nodejs error
======= ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; FLUSH PRIVILEGES;
========= https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server --- Cây sẽ cho lộc và cây sẽ cho hoa ...
|
 |