hdoj 3627

来源:互联网 发布:2016年网络新歌大全 编辑:程序博客网 时间:2024/06/06 03:32

下面的代码虽然超时,但是学习很多的STL的用法!!特别是set;

 

#include<iostream>
#include<set>
#include<cstdio>
#include<cstring>
using namespace std;
class node
{
public:
    int row;
    int clo;
  
};
 
struct com
{
 bool operator()(node x,node y)
 {
  if(x.row==y.row) return x.clo<y.clo;
  else return x.row<y.row;
 }
};
int main()
{
    int k=1;
    set<node,com> q;
    int n;
 
    while(scanf("%d",&n),n)
    {
        if(k>1) printf("/n");
        printf("Case %d:/n",k);
        q.clear();
        char op[10];
        node a;
        for(int i=1; i<=n; i++)
        {

            scanf("%s",op);
            if(strcmp(op,"add")==0)
            {

                scanf("%d%d",&a.row,&a.clo);
                q.insert(a);
            }
            else if(strcmp(op,"remove")==0)
            {
                scanf("%d%d",&a.row,&a.clo);
                q.erase(a);
            }
            else if(strcmp(op,"find")==0)
            {
                scanf("%d%d",&a.row,&a.clo);
                set<node>::iterator it=q.begin();
    for(;it!=q.end();it++)
     if((it->row)>a.row) break;
                if(it==q.end())
                {
                    printf("-1/n");
                    //continue;
                }
                else
                {
                    for(; it!=q.end(); it++)if((it->clo)>a.clo) break;
                    if(it==q.end())
                    {
                        printf("-1/n");
                        continue;
                    }
                    else
                    {
                        printf("%d %d/n",it->row,it->clo);
                    }
                }
   }
        }
        k++;
    }
return 0;
}

原创粉丝点击