九度oj代码
文章平均质量分 59
moshenlei
这个作者很懒,什么都没留下…
展开
-
九度 OJ 1053交换最大值和最小值
#include using namespace std;int main(){int n,a[20];while(cin>>n){int max,min,x,y;for(int i=0;i{cin>>a[i];}min=max=a[0];x=y=0;for(int j=0;j{if(a[j]>max){max=a[j原创 2012-11-30 14:32:46 · 569 阅读 · 0 评论 -
字符串连接
#include#includeusing namespace std;int main(){char a[205];const char *p1,*p2;string str1,str2;while(cin>>str1>>str2){int i=0;p1=str1.c_str();p2=str2.c_str();for(;i{a[i]=原创 2012-12-10 10:58:20 · 253 阅读 · 0 评论 -
重建二叉树
重建二叉树 输入某二叉树的前序遍历和中序遍历的结果,重建出该二叉树。例如:前序遍历:1 2 4 7 3 5 6 8 中序遍历:4 7 2 1 5 3 8 6分析:前序遍历的第一个值为根节点的值,然后跟的是左子树和右子树中所有的节点 中序遍历中前一部分是左子树节点,中间是根节点,后面一部分是右子树节点。转载 2012-12-09 10:10:31 · 216 阅读 · 0 评论 -
二叉树的先跟遍历,中跟遍历,后根遍历
//二叉树结点的定义。 typedef struct BiTreeNode { int data; BiTreeNode* left; BiTreeNode* right; public: BiTreeNode();//定义了一个结构体的构造函数。 }BiTreeNode,*LinkBiTree; //构转载 2012-12-09 10:40:20 · 3323 阅读 · 0 评论 -
先跟遍历和中跟遍历建树
#include using namespace std;class Node{public:int value;Node* left;Node* right;Node(int t):value(t),left(NULL),right(NULL){}Node():value(0),left(NULL),right(NULL){}};void Crea原创 2012-12-09 10:37:13 · 592 阅读 · 0 评论 -
二叉树的最长路径
要用到两个函数int Depth(BiTree T)/* 深度 */ { if(T==NULL) return(0); return 1+(Depth(T->lchild)>Depth(T->rchild)? Depth(T->lchild):Depth(T->rchild)); //选择左右孩子深度高的然后加上根节点这一层就是深度了}void Long(BiTre原创 2012-12-09 18:43:59 · 3327 阅读 · 1 评论 -
九度oj 1098 字母统计
#includeint main(){ char c; int i; while((c=getchar())!=EOF){ char zm[128]={0}; do{ zm[c]++; c=getchar(); }while(c!=原创 2012-12-01 21:54:26 · 304 阅读 · 0 评论 -
九度oj 1055 数组反序
#include #include int main(){ char a[300],*p; int len; memset(a,0,sizeof(a)); //初始化char形数组a并赋值为0 while(gets(a)) //get(a)读取一行字符串 { p=a; for(len=strlen原创 2012-12-01 21:49:54 · 382 阅读 · 0 评论 -
九度oj 1048 判断三角形类型
#include using namespace std;int main(){double a,b,c,u;int max;while(cin>>a>>b>>c){a>b?max=1:max=2;if(max=1)a>c?max=1:max=3;if(max=2)b>c?max=2:max=3;if(max==1){u=(b*b+c*c原创 2012-11-30 23:15:22 · 474 阅读 · 0 评论 -
九度 OJ 1115 数字求和
#include using namespace std;int main(){int a[6],sum;while(cin>>a[0]){sum=0;for(int i=1;i{cin>>a[i];}for(int j=1;j{if(a[j]sum+=a[j];}cout}return 0;}原创 2012-11-30 16:08:30 · 309 阅读 · 0 评论 -
九度oj 1059 abc
#include using namespace std;int main(){for(int a=0;a{for(int b=0;b{for(int c=0;c{if((a*100+b*10+c)+(b*100+c*10+c)==532)cout}}} return 0;}原创 2012-11-30 22:22:04 · 294 阅读 · 0 评论 -
九度oj 1049 字符串去特定字符
#include #include using namespace std;int main(){ char s[10000]; char c; while(cin>>s) { cin>>c; int i; f原创 2012-11-30 21:57:27 · 288 阅读 · 0 评论 -
九度 oj 1045 百鸡问题
#includeusing namespace std;int main(){int n;while(cin>>n){for(int i=0;i{for(int j=0;j{for(int k=0;k{if((5*i+3*j+(1.0/3)*k){ cout}}}}}return 0;}原创 2012-11-30 20:50:18 · 683 阅读 · 0 评论