2012年1月8日 星期日

ACM 10041 Request for Proposal

 [心得]: //0.008
1.scanf()如果遇到名字有空白,就會有問題,所以用gets()
 2. 比較需要注意的是 scanf() 後面接 gets(),gets()會多讀一個'\n',所以第二個 gets(nothing)的
    for 迴圈,counter 從0開始!
3.只要注意廠商名稱和價錢,提共的項目數量,對於項目名稱可以不用理會!
      for(i=1;i<=n;i++)
           gets(nothing);
4.ACM的格式如果沒搞清楚,就會WA,但是比較高興的是,現在自己想和寫出來的Code終於比較
   少WA了! 可以很快就AC!


#include <stdio.h>
#include <ctype.h>
#include <string.h>

struct Corp
{
  char name[90];
  float money;
  int supply;     
         
};
struct Corp Answer,Temp;

int main()
{  
    int i,n,p,q=0;
    char output[1001][90];
    char nothing[90];
    while(scanf("%d %d",&n,&p)==2)
    {
        if(n==0 || p==0)
            break;
        gets(nothing);
        int counter=0;
        Answer.supply=0;           
        for(i=1;i<=n;i++)
           gets(nothing);
                               
        while(gets(Temp.name)!=NULL)
        {
                                    
            if(isalpha(Temp.name[0]))
            {
              counter++;                         
              scanf("%f %d",&Temp.money,&Temp.supply);
              /*printf("%s\n",&Temp.name);
              printf("%f %d\n",Temp.money,Temp.supply);*/
              for(i=0;i<=Temp.supply;i++)
                 gets(nothing);
              if(Temp.supply > Answer.supply || (Temp.supply == Answer.supply && Temp.money < Answer.money))
              {
                 strcpy(Answer.name,Temp.name);
                 Answer.supply =  Temp.supply;
                 Answer.money = Temp.money;
                      
              }
          
                            
            }
             if(counter == p)
              break;     
         
        }
       strcpy(output[q],Answer.name);
       q++;
                   
    } 
    for(i=0;i<q;i++)
    {
        if(i!=0) printf("\n");      
        printf("RFP #%d\n%s\n",i+1,output[i]);
    }
  
    
 system("pause");
 //return 0;   
}

沒有留言:

張貼留言