import java.text.DecimalFormat;
創(chuàng)新互聯(lián)建站是一家朝氣蓬勃的網(wǎng)站建設(shè)公司。公司專注于為企業(yè)提供信息化建設(shè)解決方案。從事網(wǎng)站開發(fā),網(wǎng)站制作,網(wǎng)站設(shè)計,網(wǎng)站模板,微信公眾號開發(fā),軟件開發(fā),小程序設(shè)計,10多年建站對航空箱等多個行業(yè),擁有多年的營銷推廣經(jīng)驗。
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class WalkDistance {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i n; i++) {
String order = in.next();
System.out.println(new DecimalFormat("0.00").format(calDistance(order)));
}
in.close();
}
private static float calDistance(String order) {
char[] orderChar = order.toCharArray();
ListString orderList = new ArrayListString();
int num = 0;
for (int i = 0, len = orderChar.length; i len; i++) {
if (orderChar[i] = '0' orderChar[i] = '9') {
num++;
} else {
if (num == 0) {
orderList.add(String.valueOf(orderChar[i]));
} else {
StringBuffer sb = new StringBuffer();
for (int j = num; j 0; j--) {
sb.append(String.valueOf(orderChar[i - j]));
}
orderList.add(sb.toString());
orderList.add(String.valueOf(orderChar[i]));
num = 0;
}
}
if (i == len - 1 num != 0) {
StringBuffer sb = new StringBuffer();
for (int j = num - 1; j = 0; j--) {
sb.append(String.valueOf(orderChar[i - j]));
}
orderList.add(sb.toString());
}
}
Point curPoint = new Point(0, 0, 90);
for (int i = 0, len = orderList.size(); i len; i++) {
if ("R".equals(orderList.get(i))) {
curPoint.angle = (curPoint.angle - 90 + 360) % 360;
} else if ("L".equals(orderList.get(i))) {
curPoint.angle = (curPoint.angle + 90) % 360;
} else {
curPoint.setLocation(curPoint, orderList.get(i));
}
}
return curPoint.getDis();
}
static class Point {
private int x;
private int y;
private int angle;
private float dis;
public Point(int x, int y, int angle) {
this.x = x;
this.y = y;
this.angle = angle;
this.dis = (float) 0;
}
public void setLocation(Point point, String distance) {
if (point.angle == 0) {
point.x += Integer.valueOf(distance);
} else if (point.angle == 90) {
point.y += Integer.valueOf(distance);
} else if (point.angle == 180) {
point.x -= Integer.valueOf(distance);
} else {
point.y -= Integer.valueOf(distance);
}
}
public float getDis() {
return (float) Math.sqrt(this.x * this.x + this.y * this.y);
}
}
}
ServerSocket ss = null;
Socket socket = ss.accept();
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());//向客戶端發(fā)送數(shù)據(jù)的輸出流
DataInputStream dis = new DataInputStream(socket.getInputStream());//收客戶端發(fā)來的數(shù)據(jù)的輸入流
只要接收到的dis.readUTF())值
dos.writeUTF("自動回復(fù)的值");
聊天機器人也就是socket和server,你在他們里邊都加上一個線程,互相監(jiān)聽,通過輸入和輸出流傳遞信息,然后你從socket端輸入一句話,寫入流,然后server端讀取,處理一下再寫入流,然后你socket讀取,這就是一個簡單的相應(yīng)了,server端就會等待socket端的下次相應(yīng),這太簡單了,估計網(wǎng)上不會有這樣的教程,你可以大致的參考一下這個思路
在圖靈機器人注冊一個賬號,然后申請一個key,之后就可以通過http調(diào)用