...
コード:
#include <stdio.h> // fopen, fclose, feof, fgetc, fscanf, printf
#include <math.h> // sqrt
#include <string.h>
#include <stdlib.h>
#define BUF_SIZE 256
//#include <iostream>
int main(void)
{
char *fnamea = "Results16.csv";
char *fnameb = "Results17.csv";
char *fnamec = "Results18.csv";
char arr[1000][4];
char buf[2048]={0};
int(*R1)[4000];
int(*R2)[4000];
int n,m;
n = 100,m = 100;
R1 = malloc(sizeof(int)*n*m);
if(R1 == 0){
fprintf(stderr,"error\n");
exit(1);
}
R2 = malloc(sizeof(int)*n*m);
if(R2 == 0){
fprintf(stderr,"error\n");
exit(1);
}
//int R[100000];
int i,j;
int data[1000][4];
int line0 = 0;
int line1 = 0;
int line2 = 0;
FILE *fp = fopen(fnamea, "r");
if (fp == NULL) { printf("%s: file cannnot open\n", fnamea); return 1; }
//while (fgetc(fp) != '\n' && !feof(fp)) ; // skip the first line
fgets(buf,2048,fp); // skip the first line
//printf("%s",buf);
int x0[4000],y0[4000],ev0[4000],mean0[4000],min0[4000],max0[4000],area0[4000];
while(1){
//printf("hoge\n");
if( fgets(buf,2048,fp) == NULL ) break; // skip the first line
//printf("hoghoge\n");
//printf("%s",buf);
sscanf(buf,"%d,%d,%d,%d,%d,%d,%d",&ev0[line0],&area0[line0],&mean0[line0],&min0[line0],&max0[line0],&x0[line0],&y0[line0]);
//printf("%d %d %d %d\n",ev0[line0],mean0[line0],x0[line0],y0[line0]);
line0++;
}
fclose(fp);
FILE *fq = fopen(fnameb, "r");
if (fq == NULL) { printf("%s: file cannnot open\n", fnameb); return 1; }
//while (fgetc(fp) != '\n' && !feof(fp)) ; // skip the first line
fgets(buf,2048,fq); // skip the first line
//printf("%s",buf);
int x1[4000],y1[4000],ev1[4000],mean1[4000],min1[4000],max1[4000],area1[4000];
while(1){
if( fgets(buf,2048,fq) == NULL ) break; // skip the first line
//printf("%s",buf);
sscanf(buf,"%d,%d,%d,%d,%d,%d,%d",&ev1[line1],&area1[line1],&mean1[line1],&min1[line1],&max1[line1],&x1[line1],&y1[line1]);
//printf("%d %d %d %d\n",ev1[line1],mean1[line1],x1[line1],y1[line1]);
line1++;
}
fclose(fq);
FILE *fr = fopen(fnamec, "r");
if (fr == NULL) { printf("%s: file cannnot open\n", fnamec); return 1; }
//while (fgetc(fp) != '\n' && !feof(fp)) ; // skip the first line
fgets(buf,2048,fr); // skip the first line
//printf("%s",buf);
int x2[4000],y2[4000],ev2[4000],mean2[4000],min2[4000],max2[4000],area2[4000];
while(1){
//printf("hoge\n");
if( fgets(buf,2048,fr) == NULL ) break; // skip the first line
//printf("hoghoge\n");
//printf("%s",buf);
sscanf(buf,"%d,%d,%d,%d,%d,%d,%d",&ev2[line2],&area2[line2],&mean2[line2],&min2[line2],&max2[line2],&x2[line2],&y2[line2]);
//printf("%d %d %d %d\n",ev2[line2],mean2[line2],x2[line2],y2[line2]);
line2++;
}
fclose(fr);
printf("\n");
FILE *outputfile; // 出力ストリーム
outputfile = fopen("d.txt", "w"); // ファイルを書き込み用にオープン(開く)
if (outputfile == NULL) { // オープンに失敗した場合
printf("cannot open\n"); // エラーメッセージを出して
exit(1); // 異常終了
}
//printf("%d\n",x0[1]-y0[1]);
//for(int h=2;h<30;h++){
for(i=0;i<line0;i++){
for(j=0;j<line1;j++){
R1[i][j] = (x0[i]-x1[j])*(x0[i]-x1[j])+(y0[i]-y1[j])*(y0[i]-y1[j]);
//R[i*line1+j] = (x0[i]-x1[j])*(x0[i]-x1[j])+(y0[i]-y1[j])*(y0[i]-y1[j]);
//printf("%d ",R[i][j]);
for(int k=0;k<line2;k++){
R2[j][k] = (x1[j]-x2[k])*(x1[j]-x2[k])+(y1[j]-y2[k])*(y1[j]-y2[k]);
if ((R1[i][j] < 5) && (R2[j][k] < 5)){
//printf("%d %d %d\n%d %d %d\n",ev0[i],ev1[j],ev2[k],mean0[i],mean1[j],mean2[k]);
int s0 = mean0[i] - mean1[j],s2 = mean2[k] - mean1[j];
if(s0 >= 0 && s2 >= 0){
//printf("%d %d\n",s0,s2);
//printf("%d %d %d %d\n",ev1[j],mean1[j],x1[j],y1[j]);
//fprintf(outputfile, "%d %d %d %d\n",ev1[j],mean1[j],x1[j],y1[j]); // ファイルに書く
fprintf(outputfile, "%d\n",mean1[j]);
}
}
}
}
//printf("%d ",R[i*line1+j]);
}
free(R1);
free(R2);
//printf("\n");
//}
//int arr[1000][4];
fclose(outputfile);
FILE *fs;
char buf2[BUF_SIZE];
int LINE = 0;
if ((fs = fopen("d.txt", "r")) == NULL) {
return -1;
}
while (fgets(buf2, BUF_SIZE, fs) != NULL) {
LINE++;
}
printf("%d\n", LINE);
exit(0);
}