02 2012 档案
摘要:这个题就是有一个精度误差的问题 其它还好题目描述Before the 2009 elections at the European Parliament, Bill and Ted have asked their friends to make guesses about the outcome of the ballot. Now, the results have been published, so Bill and Ted want to check who was right. But checking the results of their many friends would
阅读全文
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int k,i,j,n,total,h,m,ss,flag,s,a; 5 float d; 6 scanf("%d%f",&n,&d); 7 while(scanf("%d",&a)!=EOF) 8 { 9 flag = 0;10 total = 0;11 for(i = 0 ; i < n ; i++)12 {13 if(scanf("%d:%d:%d",&h,&m,&ss)==3)14..
阅读全文
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int n,m,i,j,count,k,t,g; 5 scanf("%d", &t) ; 6 for(g = 1 ; g <= t ; g++) 7 { 8 if(g!=1) 9 puts("");10 k = 0;11 while(scanf("%d%d",&n,&m),n||m)//这里居然是|| WA了好几次。。12 {13 k++;14 co...
阅读全文
摘要:题目描述 已知一个按先序序列输入的字符序列,如abc,,de,g,,f,,,(其中逗号表示空节点)。请建立二叉树并按中序和后序方式遍历二叉树,最后求出叶子节点个数和二叉树深度。输入输入一个长度小于50个字符的字符串。输出输出共有4行:第1行输出中序遍历序列;第2行输出后序遍历序列;第3行输出叶子节点个数;第4行输出二叉树深度。对于严老师书上写的那些 表示 看得真的很吃力 换了本书 网上搜搜 东凑西凑 总算把这个题写出来了 1 #include<stdio.h> 2 #include<malloc.h> 3 typedef struct btnode 4 { 5 char
阅读全文
摘要:VC++6.0中time.h下宏定义的常量。其值为1000。VC++6.0中该符号常量定义如下: #define CLOCKS_PER_SEC 1000 此外,VC++6.0中把TC2.0中time.h下宏定义的常量CLK_TCK也宏定义成CLOCKS_PER_SEC,这样TC2.0下值为18.2的CLK_TCK在VC6.0下值变为1000。该宏定义如下: #define CLK_TCK CLOCKS_PER_SEC CLOCKS_PER_SEC,它用来表示一秒钟会有多少个时钟计时单元,其定义如下: #define CLOCKS_PER_SEC ((clock_t)1000) 可以...
阅读全文
摘要:Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers
阅读全文
摘要:Problem DescriptionThe digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is cont
阅读全文
摘要:取石子问题有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍或是围棋子等等均可。两个人轮流从堆中取物体若干,规定最后取光物体者取胜。这是我国民间很古老的一个游戏,别看这游戏极其简单,却蕴含着深刻的数学原理。下面我们来分析一下要如何才能够取胜。(一)巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。 显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜。因此我们发现了如何取胜的法则:如果n=(m+1)r+s,(r为任意自然数,s≤m),那么先取者要...
阅读全文
摘要:出自http://hi.baidu.com/xun1573/blog/item/4878002796f8ea07918f9dfd.html1.计算组合数: 一般常用C(n+1,k)=(n+1)!/k!/(n+1-k)!来计算组合数,但是这个方法中涉及到阶乘运算,数据n不能太大。用下面的方法则可以避免这个问题。帕斯卡恒等式为C(n+1,k)=C(n,k-1)+C(n,k)#include <stdio.h>#include <stdlib.h>void error(){printf("Something is wrong,Please check it!&quo
阅读全文
摘要:1 /* 2 一趟快速排序的算法是: 3 找一个记录,以它的关键字作为“枢轴”, 4 凡其关键字小于枢轴的记录均移动至该记录之前, 5 反之,凡关键字大于枢轴的记录均移动至该记录之后。 6 A[0] A[1] A[2] A[3] A[4] A[5] A[6]: 7 49 38 65 97 76 13 27 8 进行第一次交换后: 9 27 38 65 97 76 13 49 10 进行第二次交换后:11 27 38 49 97 76 13 65 12 进行第三次交换后:27 38 13 97 76 49 65 13 进行第四次交换后:...
阅读全文
摘要:不知道怎么完整而且整齐的移过来 发链接吧http://moodle.hsshn.pudong-edu.sh.cn/file.php/99/resource/ASCII.htm
阅读全文
摘要:1 /* 2 N 为奇数时 3 (1) 将1放在第一行中间一列; 4 5 6 (2) 从2开始直到n×n止各数依次按下列规则存放: 7 8 9 按 45°方向行走,如向右上10 11 12 每一个数存放的行比前一个数的行数减1,列数加113 14 15 (3) 如果行列范围超出矩阵范围,则回绕。16 17 18 例如1在第1行,则2应放在最下一行,列数同样加1;19 20 21 (4) 如果按上面规则确定的位置上已有数,或上一个数是第1行第n列时,22 23 24 则把下一个数放在上一个数的下面。25 26 */27 #include<stdio.h>...
阅读全文
摘要:1函数名称: calloc 函数原型: void * calloc(unsigned n,unsigned size); 函数功能: 分配n个数据项的内存连续空间,每个数据项的大小为size 函数返回: 分配内存单元的起始地址,如果不成功,返回0 2函数名称: free 函数原型: void free(void* p); 函数功能: 释放p所指的内存区 函数返回: 参数说明: p-被释放的指针 3函数名称: malloc 函数原型: void * malloc(unsigned size); 函数功能: 分配size字节的存储区 函数返回: 所分配的内存区地址,如果内存...
阅读全文
摘要:函数名: strcat 功 能: 字符串拼接函数 用 法: char *strcat(char *destin, char *source); 程序例:#include <string.h> #include <stdio.h>int main(void) { char destination[25]; char *blank = " ", *c = "C++", *Borland = "Borland"; strcpy(destination, Borland); strcat(destination, bl
阅读全文
摘要:n圆括号和方括号,其嵌套的顺序随意。如([]())或[([ ][ ])]等为正确的匹配;而[( ])或([ ]( )或 ( ( ) ) )均为错误的匹配。 这里只介绍了()【】其实加上{}是一样的性质 看代码 1 #include<stdio.h> 2 #include<string.h> 3 int sw(char str) 4 { 5 if(str == '(') 6 return 1; 7 else 8 if(str == ')') 9 return 9;10 else11 if(str == '['...
阅读全文
摘要:后缀式求值的方法参见我的另一篇文章 把运算符变成表达式 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int top = 0,i,k,s,num[50]; 6 char str; 7 while(scanf("%c", &str),str!='#') 8 { 9 if(str>='0'&&str<='9')10 num[++top] = str-48;11 else12 {13 switch(s
阅读全文
摘要:1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int n,m,num[10000],x,y,z,d,f = 1,i,r = 0; 6 char str[10]; 7 scanf("%d", &m); 8 for(i = 1 ; i <= m;i++) 9 scanf("%d", &num[i]);10 scanf("%d",&n);11 r = m;12 while(n--)13 {14 scanf(&quo
阅读全文
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int n,m,i,r,top = 0; 5 char stack[100]; 6 scanf("%d%d", &n,&m); 7 while(n) 8 { 9 top++;10 stack[top] = n%m;11 n = n/m;12 }13 while(top!=0)14 {15 printf("%d", stack[top]);16 top--;17 }1...
阅读全文
摘要:1 /* 将中缀表达式(a+b)转换为后缀表达式(ab+)的算法思想: 2 ·当读到数字直接送至输出队列中 3 ·当读到运算符t时, 4 a.将栈中所有优先级高于或等于t的运算符弹出,送到输出队列中; 5 b.t进栈 6 ·读到左括号时总是将它压入栈中 7 ·读到右括号时,将靠近栈顶的第一个左括号上面的运算符全部依次弹出,送至输出队列后,再丢弃左括号。 8 9 运用后缀表达式进行计算的具体做法: 10 ·建立一个栈S 11 ·从左到右读后缀表达式,读到数字就将...
阅读全文
摘要:1 #include<iostream.h> 2 #include<malloc.h> 3 struct node 4 { 5 int data; 6 struct node *next; 7 }; 8 void traverse_list(struct node *head) 9 {10 int i = 1;11 struct node *p;12 p = head->next;13 while(p)14 {15 if(i != 1)16 cout<<' ';17 cou...
阅读全文
摘要:题目描述n个人想玩残酷的死亡游戏,游戏规则如下: n个人进行编号,分别从1到n,排成一个圈,顺时针从1开始数到m,数到m的人被杀,剩下的人继续游戏,活到最后的一个人是胜利者。请输出最后一个人的编号。输入输入n和m值。输出输出胜利者的编号。示例输入5 3示例输出4提示第一轮:3被杀第二轮:1被杀第三轮:5被杀第四轮:2被杀 1 #include<iostream.h> 2 #include<malloc.h> 3 struct mon 4 { 5 int num; 6 struct mon *next; 7 }; 8 struct mon *creat(int n) 9
阅读全文
摘要:1 #include<stdio.h> 2 #include<malloc.h> 3 struct stu 4 { 5 int data ; 6 struct stu *next ; 7 }; 8 struct stu *creat(int n) 9 {10 int i;11 struct stu *head,*p;12 head = (struct stu *)malloc(sizeof(struct stu));13 head->next = NULL;14 for(i = 1 ; i <= n ;i++)15 {16 ...
阅读全文
摘要:1 #include<stdio.h> 2 #include<malloc.h> 3 struct stu 4 { 5 int data ; 6 struct stu *next ; 7 }; 8 struct stu *creat(int n) 9 {10 int i;11 struct stu *head,*p,*tail;12 head = (struct stu *)malloc(sizeof(struct stu));13 head->next = NULL;14 tail = head; 15 for(i = 1 ...
阅读全文
摘要:指针做参数传递写出下面的函数,实现计算字符串长,字符串复制功能int strlen(char *s)void strcpy( char *s, char *t)贴出你的代码 1 #include<stdio.h> 2 int strlen(char *s) 3 { 4 int n = 0; 5 while(*s++!='\0') 6 { 7 n++; 8 } 9 return n;10 }11 void strcpy( char *s, char *t)12 {13 while((*t++=*s++)!='\0');14 }15 ...
阅读全文
摘要:结构体作1.定义一个acmer结构体,包括以下信息:姓名,学号,手机号,做题数,出生日期,其中出生日期date也是一个结构体,包括年、月、日2.建立结构体数组,实现对多个同学的信息输入,输出3.实现简单的统计功能,比如统计做题数大于150的同学并输出其完整信息4.实现查找功能,包括按姓名、学号查找5.实现信息修改功能6.按做题数目进行排序(选作)7.其他功能可以自由扩展,多多益善 ^_^8.程序一个函数实现一个功能9.代码测试成功后贴在论坛上,大家互相学习借鉴 1 #include<stdio.h> 2 #include<string.h> 3 struct data
阅读全文
摘要:题目连接http://acm.hdu.edu.cn/showproblem.php?pid=1048The Hardest Problem Ever 1 #include<iostream.h> 2 #include<string.h> 3 int main() 4 { 5 int i, k, n ; 6 char x,c[201], s[20], d[4], h[11]={"ENDOFINPUT"} ; 7 while(cin.getline(c, 200) ) 8 { 9 if(strcmp(c,h) == 0)10 ...
阅读全文
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1013Digital Roots 1 #include<iostream> 2 #include<string> 3 using namespace std; 4 int devide(int n) 5 { 6 int s = 0 ; 7 while(n) 8 { 9 s = s+n%10 ;10 n = n/10 ;11 }12 return s ;13 }14 int main()15 {16 int s ;17 ...
阅读全文