import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
String m="";
LinkedList<Point> list=new LinkedList<Point>();
while(true){
m=br.readLine();
if(m.equals("0 0")){
break;
}
StringTokenizer st=new StringTokenizer(m);
int tokens=st.countTokens()/2;
int lastX=0,lastY=0;
for(int j=0;j<tokens;j++){
if(j==tokens-1){
lastX=Integer.parseInt(st.nextToken());
lastY=Integer.parseInt(st.nextToken());
if(!(lastX==0&&lastY==0)){
list.add(new Point(lastX,lastY));
}
}else{
list.add(new Point(Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken())));
}
}
if(lastX!=0||lastY!=0){
continue;
}
Point[]arr=new Point[list.size()];
for(int i=0;i<arr.length;i++){
arr[i]=list.remove();
}
Arrays.sort(arr);
boolean getit=false;
boolean checked[][]=new boolean[arr.length][arr.length];
for(int i=0;i<arr.length;i++){
for(int j=i+1;j<arr.length;j++){
if(checked[i][j]){
continue;
}
LinkedList<Point> temp=new LinkedList<Point>();
LinkedList<Integer> zs=new LinkedList<Integer>();
temp.add(arr[i]);
temp.add(arr[j]);
boolean tempL[]=new boolean[arr.length];
for(int z=j+1;z<arr.length;z++){
if(checked[i][z]||checked[j][z]){
continue;
}
if(coolinear(arr[i],arr[j], arr[z])){
temp.add(arr[z]);
checked[i][j]=true;
checked[j][z]=true;
checked[i][z]=true;
zs.add(z);
}
}
if(temp.size()>2){
if(!getit){
sb.append("The following lines were found: \n");
}
getit=true;
while(!temp.isEmpty()){
sb.append(temp.remove().out());
}
sb.append("\n");
}
int[]zsArr=new int[zs.size()];
for(int k=0;k<zsArr.length;k++){
zsArr[k]=zs.remove();
}
for(int k=0;k<zsArr.length;k++){
for(int l=k+1;l<zsArr.length;l++){
checked[zsArr[k]][zsArr[l]]=true;
}
}
}
}
if(!getit){
sb.append("No lines were found\n");
}
}
System.out.print(sb);
}
static boolean coolinear(Point a,Point b,Point c){
return ((a.getY())-(b.getY()))*((a.getX())-(c.getX()))==
((a.getY())-(c.getY()))*((a.getX())-(b.getX()));
}
}
class Point implements Comparable<Point> {
private int x;
private int y;
public Point(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;
}
@Override
public int compareTo(Point o) {
if(this.x>o.getX()){
return 1;
}else if(this.x<o.getX()){
return -1;
}
if(this.y>o.getY()){
return 1;
}else{
return -1;
}
}
public String out(){
String ans=String.format("(%4d,%4d)", this.x,this.y);
return ans;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
String m="";
LinkedList<Point> list=new LinkedList<Point>();
while(true){
m=br.readLine();
if(m.equals("0 0")){
break;
}
StringTokenizer st=new StringTokenizer(m);
int tokens=st.countTokens()/2;
int lastX=0,lastY=0;
for(int j=0;j<tokens;j++){
if(j==tokens-1){
lastX=Integer.parseInt(st.nextToken());
lastY=Integer.parseInt(st.nextToken());
if(!(lastX==0&&lastY==0)){
list.add(new Point(lastX,lastY));
}
}else{
list.add(new Point(Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken())));
}
}
if(lastX!=0||lastY!=0){
continue;
}
Point[]arr=new Point[list.size()];
for(int i=0;i<arr.length;i++){
arr[i]=list.remove();
}
Arrays.sort(arr);
boolean getit=false;
boolean checked[][]=new boolean[arr.length][arr.length];
for(int i=0;i<arr.length;i++){
for(int j=i+1;j<arr.length;j++){
if(checked[i][j]){
continue;
}
LinkedList<Point> temp=new LinkedList<Point>();
LinkedList<Integer> zs=new LinkedList<Integer>();
temp.add(arr[i]);
temp.add(arr[j]);
boolean tempL[]=new boolean[arr.length];
for(int z=j+1;z<arr.length;z++){
if(checked[i][z]||checked[j][z]){
continue;
}
if(coolinear(arr[i],arr[j], arr[z])){
temp.add(arr[z]);
checked[i][j]=true;
checked[j][z]=true;
checked[i][z]=true;
zs.add(z);
}
}
if(temp.size()>2){
if(!getit){
sb.append("The following lines were found: \n");
}
getit=true;
while(!temp.isEmpty()){
sb.append(temp.remove().out());
}
sb.append("\n");
}
int[]zsArr=new int[zs.size()];
for(int k=0;k<zsArr.length;k++){
zsArr[k]=zs.remove();
}
for(int k=0;k<zsArr.length;k++){
for(int l=k+1;l<zsArr.length;l++){
checked[zsArr[k]][zsArr[l]]=true;
}
}
}
}
if(!getit){
sb.append("No lines were found\n");
}
}
System.out.print(sb);
}
static boolean coolinear(Point a,Point b,Point c){
return ((a.getY())-(b.getY()))*((a.getX())-(c.getX()))==
((a.getY())-(c.getY()))*((a.getX())-(b.getX()));
}
}
class Point implements Comparable<Point> {
private int x;
private int y;
public Point(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;
}
@Override
public int compareTo(Point o) {
if(this.x>o.getX()){
return 1;
}else if(this.x<o.getX()){
return -1;
}
if(this.y>o.getY()){
return 1;
}else{
return -1;
}
}
public String out(){
String ans=String.format("(%4d,%4d)", this.x,this.y);
return ans;
}
}
No comments:
Post a Comment