import java.util.List;
import java.util.Scanner;
import java.util.*;
class Points{
int x;
int y;
public Points(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getArea(){
return x*x+y*y;
}
}
public class Test {
// 本题为考试单行多行输入输出规范示例,无需提交,不计分。
public static boolean judge(int a,int b,Set<Integer> set){
if(set.contains(a)&&set.contains(b))
return true;
return false;
}
public static void main(String[] args) {
test1();
test2();
test3();
}
public static void test3(){
Scanner in = new Scanner(System.in);
while (in.hasNext()) {// 注意,如果输入是多个测试用例,请通过while循环处理多个测试用例
Set<Integer> set=new HashSet();
String all=in.nextLine();
String[] array=all.split(" ");
int n=Integer.valueOf(array[0]);
int m=Integer.valueOf(array[1]);
if(n<1||m<1||n>100000||m>100000)
System.out.println("NULL");
else{
for(int i=0;i<m;i++){
String list=in.nextLine();
String[] info=list.split(" ");
int a=Integer.valueOf(info[0]);
int b=Integer.valueOf(info[1]);
int c=Integer.valueOf(info[2]);
if(a<1||b<1||a>n||b>n||(c!=1&&c!=0)){
System.out.println("da pian zi");
}else{
if(c==0){
set.add(a);
set.add(b);
}else{
//判断是否是一个队伍
if(judge(a,b,set)){
System.out.println("we are a team");
}else{
System.out.println("we are not a team");
}
}
}
}
}
}
}
public static void test1() {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {// 注意,如果输入是多个测试用例,请通过while循环处理多个测试用例
String all=in.nextLine();
String[] array=all.split(",");
//排序
int size=array.length;
for(int i=0;i<size-1;i++){
for(int j=i+1;j<size;j++){
int ilength=array[i].length();
int jlength=array[j].length();
if(ilength<jlength){
if(array[j].startsWith(array[i])){
String temp=array[j];
array[j]=array[i];
array[i]=temp;
} else if(array[i].compareTo(array[j])>0){
exchange(array,i,j);
}
}
else if(array[i].compareTo(array[j])>0){
exchange(array,i,j);
}
}
}
StringBuffer sb=new StringBuffer();
for(int i=array.length-1;i>=0;i--){
sb.append(array[i]);
}
System.out.println(sb.toString());
}
}
public static void exchange(String[] array,Integer i,Integer j){
String temp=array[j];
array[j]=array[i];
array[i]=temp;
}
public static void test2(){
Scanner in = new Scanner(System.in);
while (in.hasNext()) {// 注意,如果输入是多个测试用例,请通过while循环处理多个测试用例
List<Points> list=new ArrayList<Points>();
String all=in.nextLine();
char[] array=all.toCharArray();
int start=0,end=0;
for(int i=0;i<array.length;i++){
char value=array[i];
if(value=='('){
start=i+1;
}else if(value==')'){
end=i;
}
if(start>0&&end>0){
String b=all.substring(start,end);
String[] split = b.split(",");
if(split[0].startsWith("0")||split[1].startsWith("0")){
continue;
}else{
list.add(new Points(Integer.valueOf(split[0]),Integer.valueOf(split[1])));
}
start=0;
end=0;
}
}
if(list.size()==0){
System.out.println("(0,0)");
}
else{
list.sort(Comparator.comparing(Points::getArea).reversed());
Points points = list.get(0);
System.out.println("("+points.getX()+","+points.getY()+")");
}
}
}
}
华为OD 机试3题(通过率60%,80%,75%)
最新推荐文章于 2024-07-18 08:16:28 发布