十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
import java.text.DecimalFormat;
创新互联建站是一家朝气蓬勃的网站建设公司。公司专注于为企业提供信息化建设解决方案。从事网站开发,网站制作,网站设计,网站模板,微信公众号开发,软件开发,小程序设计,10多年建站对航空箱等多个行业,拥有多年的营销推广经验。
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());//向客户端发送数据的输出流
DataInputStream dis = new DataInputStream(socket.getInputStream());//收客户端发来的数据的输入流
只要接收到的dis.readUTF())值
dos.writeUTF("自动回复的值");
聊天机器人也就是socket和server,你在他们里边都加上一个线程,互相监听,通过输入和输出流传递信息,然后你从socket端输入一句话,写入流,然后server端读取,处理一下再写入流,然后你socket读取,这就是一个简单的相应了,server端就会等待socket端的下次相应,这太简单了,估计网上不会有这样的教程,你可以大致的参考一下这个思路
在图灵机器人注册一个账号,然后申请一个key,之后就可以通过http调用