487-3279 - PKU 1002
来源:互联网 发布:我的世界0.14js导入 编辑:程序博客网 时间:2024/04/28 10:24
/**//*
Name: 487-3279 - PKU 1002
Author: Mars
Description: 本来用STL的MAP写的,超了N次时。。只得自己写了个二分查找树
Result: 2265308 bestzsx 1002 Accepted 2512K 998MS C++ 1753B 2007-06-12 23:50:54
*/
#include <iostream>
using namespace std;
int flag;
class tNode ...{
public:
tNode();
tNode(int value);
int val;
int counts;
tNode * lch, * rch;
};
tNode::tNode() ...{
val = 0;
counts = 0;
lch = rch = NULL;
}
tNode::tNode(int value) ...{
val = value;
counts = 1;
lch = rch = NULL;
}
class BSTree ...{
public:
BSTree();
tNode * insert(tNode *);
void mfs(tNode *);
tNode * root;
};
BSTree::BSTree() ...{
root = NULL;
}
tNode * BSTree::insert(tNode * z) ...{
tNode * y = NULL;
tNode * x = root;
while (x!=NULL) ...{
y = x;
if (z->val == x->val) ...{
++x->counts;
break;
} else if (z->val < x->val) ...{
x = x->lch;
} else ...{
x = x->rch;
}
}
if (NULL==x) ...{
if (NULL==y) root = z;
else ...{
if (z->val < y->val)
y->lch = z;
else
y->rch = z;
}
}
return z;
}
void BSTree::mfs(tNode * tn) ...{
if (NULL==tn) return;
mfs(tn->lch);
if (tn->counts>1) ...{
if (!flag) flag = 1;
cout.width(3);
cout<<tn->val/10000;
cout<<"-";
cout.width(4);
cout<<tn->val%10000;
cout<<" "<<tn->counts<<endl;
}
mfs(tn->rch);
}
int m1002() ...{
int i,N,val;
char c;
BSTree * bst = new BSTree();
flag = 0;
cin>>N;
c = cin.get(); // remove ' '
for (i=0;i<N;++i) ...{
// input
val = 0;
while ((c=cin.get())!=' ') ...{
if (c>='0' && c<='9')
val=val*10+c-'0';
else if (c>='A' && c<'Q')
val=val*10+(c-'A')/3+2;
else if (c>'Q' && c<'Z')
val=val*10+(c-'Q')/3+7;
}
bst->insert(new tNode(val));
// solve
}
cout.fill('0');
bst->mfs(bst->root);
if (!flag) cout<<"No duplicates. ";
delete bst;
return 0;
}
Name: 487-3279 - PKU 1002
Author: Mars
Description: 本来用STL的MAP写的,超了N次时。。只得自己写了个二分查找树
Result: 2265308 bestzsx 1002 Accepted 2512K 998MS C++ 1753B 2007-06-12 23:50:54
*/
#include <iostream>
using namespace std;
int flag;
class tNode ...{
public:
tNode();
tNode(int value);
int val;
int counts;
tNode * lch, * rch;
};
tNode::tNode() ...{
val = 0;
counts = 0;
lch = rch = NULL;
}
tNode::tNode(int value) ...{
val = value;
counts = 1;
lch = rch = NULL;
}
class BSTree ...{
public:
BSTree();
tNode * insert(tNode *);
void mfs(tNode *);
tNode * root;
};
BSTree::BSTree() ...{
root = NULL;
}
tNode * BSTree::insert(tNode * z) ...{
tNode * y = NULL;
tNode * x = root;
while (x!=NULL) ...{
y = x;
if (z->val == x->val) ...{
++x->counts;
break;
} else if (z->val < x->val) ...{
x = x->lch;
} else ...{
x = x->rch;
}
}
if (NULL==x) ...{
if (NULL==y) root = z;
else ...{
if (z->val < y->val)
y->lch = z;
else
y->rch = z;
}
}
return z;
}
void BSTree::mfs(tNode * tn) ...{
if (NULL==tn) return;
mfs(tn->lch);
if (tn->counts>1) ...{
if (!flag) flag = 1;
cout.width(3);
cout<<tn->val/10000;
cout<<"-";
cout.width(4);
cout<<tn->val%10000;
cout<<" "<<tn->counts<<endl;
}
mfs(tn->rch);
}
int m1002() ...{
int i,N,val;
char c;
BSTree * bst = new BSTree();
flag = 0;
cin>>N;
c = cin.get(); // remove ' '
for (i=0;i<N;++i) ...{
// input
val = 0;
while ((c=cin.get())!=' ') ...{
if (c>='0' && c<='9')
val=val*10+c-'0';
else if (c>='A' && c<'Q')
val=val*10+(c-'A')/3+2;
else if (c>'Q' && c<'Z')
val=val*10+(c-'Q')/3+7;
}
bst->insert(new tNode(val));
// solve
}
cout.fill('0');
bst->mfs(bst->root);
if (!flag) cout<<"No duplicates. ";
delete bst;
return 0;
}
- 487-3279 - PKU 1002
- 487-3279 - PKU 1002
- PKU 1002 487-3279
- pku 1002 487-3279
- PKU ACM 1002 487-3279
- pku oj 1002 487-3279
- PKU 1002 487-3279 问题的解决
- PKU ACM 1002 487-3279 C++实现
- PKU 1002
- pku 1002
- PKU-1002
- PKU 1002
- Pku acm 1002 487-3279 排序算法解题报告(一) ----二叉查找数(BST)
- POJ 1002求487-3279解题报告——【PKU ACM】
- PKU OJ 1002(487-3279)电话号码解题方法与个人最简短代码
- 二叉排序树求解pku 1002
- PKU 1002 感想
- pku 1002 解题报告
- 中秋节快乐
- 如何利用客户端缓存对网站进行优化?
- pku_Exponentiation_1001
- 如何利用客户端缓存对网站进行优化?
- 秋风秋雨正是读书时《CSS实战手册》(CSS: The Missing Manual)中秋佳节登场亮相了
- 487-3279 - PKU 1002
- ASP.NET 页生命周期概述
- PKU题解
- GridView实现双击进行编辑,更新
- Windows Server 2008 十项重要新技术
- 堵车,迟到15分钟
- 日期格式转化总结
- 利用ASP.NET输出指定内容的WORD、EXCEL、TXT、HTM等类型的文档
- 浅谈数据库设计技巧