2017年360公司校招笔试编程第一题
(服务端开发工程师-Java职位)
---------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Main {
/** 2017年360公司校招 编程1题
*
* */
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String line = in.nextLine();
String line1 = in.nextLine();
String line2 = in.nextLine();
//去程
Boolean b1 = line.contains(line1);
Boolean b2 = false;
Boolean b3 = false;
if (b1 == true) {
String line3 = line.substring(line.indexOf(line1) + line1.length());
b2 = line3.contains(line2);
if (b2 == true) {
b3 = true;
}
}
//返程
StringBuilder sb1 = new StringBuilder(line);
sb1.reverse(); //输入的旗帜颜色逆序排列
Boolean c1 = sb1.toString().contains(line1);
Boolean c2 = false;
Boolean c3 = false;
if (c1 == true) {
String line3 = sb1.toString().substring(sb1.toString().indexOf(line1) + line1.length());
c2 = line3.contains(line2);
if (c2 == true) {
c3 = true;
}
}
if (b3 == true && c3 == true) {
System.out.println("both");
} else if (b3 == true && c3 == false) {
System.out.println("forward");
} else if (b3 == false && c3 == true) {
System.out.println("backward");
} else {
System.out.println("invalid");
}
}
}
}