Submission #3482

# Submission time Handle Problem Language Result Execution time Memory
3482 2013-08-31T06:07:16 Z hhosu107 Divide into triangle (kriii1_D) C++
Compilation error
0 ms 0 KB
#include<stdio.h>
#include<math.h>

#define PI (4*atan(1.0))

int N;

int no[900];
int dot[900][2];
double angle[900];
int temp;
double temp2;

void swap(int *, int *);
void swap2(double *, double *);

int main(){
	int i = 0;
	scanf("%d", &N);
	while(N--){
		do{
			scanf("%d %d", &dot[i][0], &dot[i][1]);
			angle[i] = atan2((double)dot[i][1], (double)dot[i][0]);
			if(angle[i] < 0.0) 
				angle[i] += 2 * PI;
			i++;
			no[i - 1] = i;
		}while(i % 3);
	}
	int j, k;
	for(j = 0; j < i - 1; j++){
		for(k = j + 1; k < i; k++){
			if(angle[j] > angle[k]){
				swap2(&angle[j], &angle[k]);
				swap(&dot[j][0], &dot[k][0]);
				swap(&dot[j][1], &dot[k][1]);
				swap(&no[j], &no[k]);
			}
			else if(angle[j] == angle[k]){
				if(abs(dot[j][0]) > abs(dot[k][0])){
					swap2(&angle[j], &angle[k]);
					swap(&dot[j][0], &dot[k][0]);
					swap(&dot[j][1], &dot[k][1]);
					swap(&no[j], &no[k]);
				}
			}
		}
	}
	j = 0;
	do{
		printf("%d %d %d\n", no[3 * j], no[3 * j + 1], no[3 * j + 2]);
		j++;
	}while(j * 3 != i);
	return 0;
}

void swap(int *x, int *y){
	int temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

void swap2(double *x, double *y){
	double temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

Compilation message

D.cpp: In function 'int main()':
D.cpp:40:21: error: 'abs' was not declared in this scope
D.cpp:19:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
D.cpp:22:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]