Thread: [Solution Needed] Structures questions

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    7

    [Solution Needed] Structures questions

    Hi all, It is me again.. >_< I have these questions asked by my lecturer which i cant answer. Could any kind soul please help me =D

    Create a structure of a university ACM ICPC team that contains 6 strings of maximum 50
    characters (described in details below), number of problems solved (an integer),
    and finally their penalty points (an integer).
    Each of the 6 string represents one name. The first name is the team name, then the institution
    name, then the coach name, and finally the last three names are the contestant names.
    See this Wikipedia page for more details:
    ACM International Collegiate Programming Contest - Wikipedia, the free encyclopedia

    b. After the structure type is created, create three teams: t1, t2, t3, with the following data from a
    recent mock / training contest:
    Code:
    t1 = {NUSSOC1, NUS, Steven, Victor, Adhiraj, Hung, 4, 448}
    t2 = {NUSSOC2, NUS, Steven, Duc, Tien, Phong, 6, 716}
    t3 = {NUSSOC3, NUS, Steven, Haocong, BiRan, Daniel, 5, 755}

    c. Finally, use C code to do these operations:
    1. Check which one between struct t1, t2, or t3 is rank 1 in this ‘mock contest’.
    In ICPC, team is ranked based on number of problems solved.
    The answer is unique in this instance.
    2. Check which one between t1, t2, or t3 has team name equals to “NUSSOC1”,
    then display the coach name of that team.
    3. Suppose team t3 (NUSSOC3) solved another problem at minute 250, increased their number
    of problems solved by 1 and penalty points by 250. Update t3 and print the updated number
    of problems solved and the penalty points of t3.


    There is 3 parts in this question.

    Thank you very much =D

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What part are you having problems with? Show your attempt, any errors you get, and specifically what you can or cannot figure out.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    7
    Quote Originally Posted by quzah View Post
    What part are you having problems with? Show your attempt, any errors you get, and specifically what you can or cannot figure out.


    Quzah.
    Hi quzah thanks for the reply.
    Here is what i did.. but when i compare the team name.. it doesnt work. and i dont know how to approach the 3rd portion

    Code:
    #include <stdio.h>
    #include <string.h>
    
    struct icpc{
    	char team[8];
    	char insitution[8];
    	char coach[8];
    	char c1[8];
    	char c2[8];
    	char c3[8];
    	int solved, penalty;
    };
    
    
    int main()
    {
       struct icpc t1 = {"NUSSOC1","NUS","Steven","Victor","Adhiraj","Hung", 4, 448}, t2 = {"NUSSOC2","NUS","Steven","Duc","Tien","Phong", 6, 716}, t3 = {"NUSSOC3","NUS","Steven","Haocong","BiRan","Daniel", 5, 755};
    
       if(t1.solved>t2.solved && t1.solved>t3.solved)
    	   printf("Team 1 is rank 1.\n");
       if(t2.solved>t1.solved && t2.solved>t3.solved)
    	   printf("Team 2 is rank 1.\n");
       if(t3.solved>t1.solved && t3.solved>t2.solved)
    	   printf("Team 3 is rank 1.\n");
    
       if(t1.team == "NUSSOC1"){
    	   printf("%s\n",t1.coach);
           printf("12345\n");
       }
       if(t2.team == "NUSSOC1")
    	   printf("%s\n",t2.coach);
       if(t2.team == "NUSSOC1")
    	   printf("%s\n",t3.coach);
    
    }

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    (26): warning C4130: '==' : logical operation on address of string constant
    (30): warning C4130: '==' : logical operation on address of string constant
    (32): warning C4130: '==' : logical operation on address of string constant

    Use strcmp to compare strings, not ==. Using == will compare a pointer to another pointer, which will never be true.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions about structures passing through functions
    By nareik9394 in forum C Programming
    Replies: 1
    Last Post: 03-18-2009, 06:19 PM
  2. Data structures basic questions
    By WarDoGG in forum C Programming
    Replies: 7
    Last Post: 07-11-2008, 09:42 AM
  3. A questions about structures
    By HAssan in forum C Programming
    Replies: 1
    Last Post: 04-28-2007, 07:41 PM
  4. COntrol structures and functions questions
    By angelicscars in forum C Programming
    Replies: 1
    Last Post: 11-21-2005, 11:50 AM
  5. I have some questions about data structures and algorithms
    By Tonyukuk in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2003, 01:31 PM