- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main(){
FILE *filein, *fileout;
char fname1[15], fname2[15];
int n, m;
int i, j;
printf("Enter name of input file: "); scanf("%s", &fname1);
printf("Enter name of output file: "); scanf("%s", &fname2);
filein=fopen(fname1, "r");
fileout=fopen(fname2, "w");
if(filein==NULL){
fprintf(stderr, "\nError: can't open file \"%s\"\n\n", fname1);
fclose(filein);
fclose(fileout);
getch();
}
else{
fscanf(filein, "%d%d", &n, &m);
char ch[m][n];
int array[m][n];
int V[m][n];
for(i=0;i<m;i++){
for(j=0;j<n;j++){
V[i][j]=0;
}
}
for(i=0;i<m;i++){
for(j=0;j<n;j++){
fscanf(filein, "%s", &ch[i][j]);
if(ch[i][j]=='+') array[i][j]=1;
else if(ch[i][j]=='-') array[i][j]=0;
}
}
int sum;
for(i=0;i<m;i++){
sum=0;
for(j=0;j<n;j++){
sum+=array[i][j];
}
if(sum==1){
for(j=0;j<n;j++){
V[i][j]=array[i][j];
}
}
else continue;
}
int mm=0, c;
for(i=0;i<m;i++){
for(j=0;j<n;j++){
mm+=V[i][j];
}
}
c = m-mm;
int VoteArray[n];
for(j=0;j<n;j++){
sum=0;
for(i=0;i<m;i++){
sum+=V[i][j];
VoteArray[j]=sum;
}
}
float percent[n];
float per;
per = 100/(float)c;
for(i=0;i<n;i++){
if((percent[i]=per*VoteArray[i])>=7.0) fprintf(fileout, "%d ", i+1);
}
}
fclose(fileout);
fclose(filein);
puts("\nMission comleted\nPress any key...\n");
getch();
}