how to use stack combining with if?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a set of numbers representing student IDs and these students need
special attention to their grades.

      220048 311611 519804 797736 909164
      a b a c e

in fact the grade file is in a format like this:

1    a
2    a
3    c
4    b
5    a
6    b
7    ...
4000000    a

I would like to use the student IDs to obtain their corresponding grades,
stack seems to be a solution but I don't know how to combine it elegantly
with "if". Does anybody have a suggestion? Thanks.

Re: how to use stack combining with if?

Quoted text here. Click to load it

Furthermore, we have to look for whether any student in particular classes
not taking the exam, e.g.

class A:             578732 578886

class B:             581965 582162

class C:             960063 960325


So again as I have the file
578732 578886
581965 582162

how can i check the presence of exam, giving that the file this time is not
with numbers monotonically increasing?

Re: how to use stack combining with if?

Quoted text here. Click to load it

Your descriptions are not clear to me at all, but the general approach
to this kind of problem is to read the shorter or less organized data
into memory, creating a data structure that is is well organized and
targeted to make the main task easier. In your case, where you want to
check if a given number appears in the "special attention list" or the
"didn't take exam" list, a hash seems to be quite convenient.
And then just loop through the larger list one by one checking if the
current element occurs in either of your predetermined check lists.

If you get even more special lists, then the opposite approach might be
more useful: reading the whole student list into memory once and then
walking through your special lists one by one.

I have no idea what you mean by "stack combining with if". Those two
have about nothing in common at all.

Site Timeline