您的位置:首页 > 大数据 > 人工智能

HIT summer training contest 08——练练手

2011-08-01 22:37 423 查看
在家没事干就要多做做比赛才是。。。

C题是搜索题 N个数字之间放N-1个"+","-","*" ,"/"

使每位不存在为k的数字。。。

注意点,超int,注意除数不为0,当结果为0是特判

View Code

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<set>
#include<map>
using namespace std;

bool hash[100][10000];

struct data
{
int no;
char ss[299];
}node1[909];

bool cmp(data a,data b)
{
if(a.no==b.no)
return strcmp(a.ss,b.ss)<0;
return a.no>b.no;
}

struct stu
{
int no;
bool use;
};

int main()
{
char temp[299];
int add=-1;
set<string> set1;
gets(temp);

map<string,stu>mm;

while(1)
{

if(temp[0]>='A'&&temp[0]<='Z')
{
add++;
set<string> ss;
strcpy(node1[add].ss,temp);

while(gets(temp),(temp[0]<'A'||temp[0]>'Z')&&temp[0]!='1'&&temp[0]!='0')
{
ss.insert(temp);

}
if(temp[0]=='1'&&temp[0]=='0')break;

set<string>::iterator pp;

int all=0;
for(pp=ss.begin();pp!=ss.end();pp++)
{
if(mm.find(*pp)==mm.end())
{
mm[*pp].no=add;
all++;
}
else
{
if(mm[*pp].use==0)
{
node1[mm[*pp].no].no--;
mm[*pp].use=1;
}
}
}

node1[add].no=all;

}
if(temp[0]=='1')
{
mm.clear();
int i;
sort(&node1[0],&node1[add+1],cmp);
for(i=0;i<=add;i++)
{
printf("%s %d\n",node1[i].ss,node1[i].no);
}
for(i=0;i<=100;i++)
{
node1[i].no=0;
}
add=-1;
gets(temp);
}
if(temp[0]=='0')
return 0;

}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐