I need to make a program that takes in:
- The total number of characters to be compared
- The character to evaluate
- A comparisons between the character to evaluate and other characters
The output of the program should be "YES" if the selected character is the greatest, and otherwise "NO".
The input is obtained from 'input.txt', where:
- The first number,
n
, is the number of characters - The second number,
k
, is the selected character - Each subsequent line is a character comparison with the greater on the left and the smaller on the right
- A terminating line containing only a '0'
But how can I compare the values when there are more than 2 characters?
For example this 'input.txt' should result in "YES" because k
is '1', and '1' is greater than the other 2 characters:
3 1
1 2
1 3
0
This example should result in "NO" because k
is only greater than 1 character:
3 2
2 3
0
Here is my code, I had intended to use x
and y
to represent the first and second character on a comparison line:
#include <iostream>
#include <fstream>
using namespace std;
void main(){
int n;
char k;
char x;
char y;
char max=1;
unsigned char end;
ifstream input;
input.open("input.txt");
input >> n;
input >> k;
while (end!=0){
/*Here is the part I want an advance
the program needs to compare many character ids (almost 50 of them),
but I cannot imagine how to do that*/
end = 0;
}
ofstream output;
output.open("output.txt");
if (k == max)
output << "YES";
else
output << "NO";
}