C
C#9h ago
Archion

C# homework

I don't know if i made a good code or not
15 Replies
Archion
ArchionOP9h ago
using System;
using System.IO;

namespace Beadando2;
class Program{
static void Main(string[] args){
FileStream fs = new FileStream("be2.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);

int n = Convert.ToInt32(sr.ReadLine());
int[] H = new int[n];
int[] P = new int[n];
int[] Mp= new int[n];

int temp = 0;
while(!sr.EndOfStream)
{
string[] line = sr.ReadLine().Split(' ');
H[temp]=Convert.ToInt32(line[0]);
P[temp]=Convert.ToInt32(line[1]);
Mp[temp]=Convert.ToInt32(line[2]);

temp++;
}
sr.Close();
fs.Close();

int[] ki=new int[2];


temp = 0;
for(int i=1;i<n;i++){
if(H[temp]>3){
temp=i;
continue;
}

if(H[i]<=3){
if(P[i]*60+Mp[i] > P[temp]*60+Mp[temp]){
temp=i;
}
}
}
ki[0]=temp;
temp = 0;
for(int i=1;i<n;i++){
if(H[temp]>3){
temp=i;
continue;
}

if(H[i]<=3){
if(P[i]*60+Mp[i] < P[temp]*60+Mp[temp]){
temp=i;
}
}
}
ki[1] = temp;
Console.WriteLine((ki[0]+1) + " " + (ki[1]+1));
}
}
using System;
using System.IO;

namespace Beadando2;
class Program{
static void Main(string[] args){
FileStream fs = new FileStream("be2.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);

int n = Convert.ToInt32(sr.ReadLine());
int[] H = new int[n];
int[] P = new int[n];
int[] Mp= new int[n];

int temp = 0;
while(!sr.EndOfStream)
{
string[] line = sr.ReadLine().Split(' ');
H[temp]=Convert.ToInt32(line[0]);
P[temp]=Convert.ToInt32(line[1]);
Mp[temp]=Convert.ToInt32(line[2]);

temp++;
}
sr.Close();
fs.Close();

int[] ki=new int[2];


temp = 0;
for(int i=1;i<n;i++){
if(H[temp]>3){
temp=i;
continue;
}

if(H[i]<=3){
if(P[i]*60+Mp[i] > P[temp]*60+Mp[temp]){
temp=i;
}
}
}
ki[0]=temp;
temp = 0;
for(int i=1;i<n;i++){
if(H[temp]>3){
temp=i;
continue;
}

if(H[i]<=3){
if(P[i]*60+Mp[i] < P[temp]*60+Mp[temp]){
temp=i;
}
}
}
ki[1] = temp;
Console.WriteLine((ki[0]+1) + " " + (ki[1]+1));
}
}
the task is: there is race where it is recorded in the first line the number of race he ran H array is the places he got P array is the minutes it needed to finish and Mp array is the seconds i had to get the fastest race first and last index so max and min but the catch is the place must be at least 3 or 2 or 1
10
7 9 6
7 4 29
4 0 12
6 2 30
2 4 50
3 1 39
7 5 6
9 2 18
10 8 6
3 1 5
10
7 9 6
7 4 29
4 0 12
6 2 30
2 4 50
3 1 39
7 5 6
9 2 18
10 8 6
3 1 5
this input file and it should write 4 and 5 but mine is 4 and 9
Pobiega
Pobiega9h ago
can you explain a bit more about the "catch" and the "fastest race first and last index" parts? also, wouldnt it be easier to represent each race as an object instead of an array of each metric? oh okay I get it now. Yeah this would be a lot easier if you modelled it as an object, like a record
Archion
ArchionOP9h ago
no because no struct or class sry
Pobiega
Pobiega9h ago
wdym? are you not allowed to use structs or classes for this particular homework?
Archion
ArchionOP9h ago
i am lazy to do in specification
Pobiega
Pobiega9h ago
?
Archion
ArchionOP9h ago
specification -> structogram -> code
Pobiega
Pobiega9h ago
silly for a thing like this but to answer your question... this is not good code it can easily be done while reading from the file, as opposed to reading all the values into weird arrays first, or even better and readable with using an object to hold the values
Archion
ArchionOP9h ago
sir but the code is good semantically?
Pobiega
Pobiega9h ago
no
Archion
ArchionOP9h ago
so it doesn't do what it has to?
Pobiega
Pobiega9h ago
I mean you just said that yourself.
No description
Archion
ArchionOP9h ago
broooo they are giving me a headache probably the output file is bad
Pobiega
Pobiega9h ago
your expected value is wrong, yes look at race 5 3 1 39 vs race 9 3 1 5 race 9 is the fastest top 3 race at 65 total seconds race 4 is the slowest top 3 race, at 290 seconds
FusedQyou
FusedQyou9h ago
Please use proper naming for your variable names :oh: How is anybody supposed to read this What is H? What is P? What is Mp??
Want results from more Discord servers?
Add your server