您当前的位置: 首页 >  算法

星许辰

暂无认证

  • 6浏览

    0关注

    466博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

杭电OJ第11页2070~2074算法题(C语言)

星许辰 发布时间:2021-01-17 12:49:47 ,浏览量:6

目录
  • 2070.Fibbonacci Number
  • 2071.Max Num
  • 2072.单词数
  • 2073.无限的路
  • 2074.叠筐

2070.Fibbonacci Number
Problem Description
Your objective for this question is to develop a program which will 
generate a fibbonacci number. The fibbonacci function is defined as such:

f(0) = 0
f(1) = 1
f(n) = f(n-1) + f(n-2)

Your program should be able to handle values of n in the range 0 to 50.
 
Input
Each test case consists of one integer n in a single line where 0≤n≤50. 
The input is terminated by -1.
 
Output
Print out the answer in a single line for each test case.
 
Sample Input
3
4
5
-1
 
Sample Output
2
3
5

Hint
Note:
you can use 64bit integer: __int64

分析:直接利用题目给出的递推式编写代码即可。

#include 

void Fibbonacci(){
	__int64 fib[51]={0,1};
	int i,n;
	for(i=2;i=0 && nmax){
					max=h;
				}
			}	
			printf("%.2lf\n",max);	
		}
	}
}
2072.单词数
Problem Description
lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。

Input
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。

Output
每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。

Sample Input
you are my friend
#

Sample Output
4

分析:每输入一个单词用数组word保存,并且与二维数组words中的单词进行比较,若刚输入的单词不在words中,则将其保存到其中,并且单词数量count加一。

#include 
#include 

void NumberWords(){
	//二维数组st的每一行用来保存一个单词,且每行的单词都不一样 
	char words[100][1000];
	char word[1000]="";
    char c;
	int i,j,count,k;
    while((c=getchar())!='#'){
        word[0]=c;
		j=count=0;
		k=1;
        while(c!='\n'){
        	//将一个完整的单词保存到s中 
            while((c=getchar())!=' ' && c!='\n'){
				word[k++]=c;
			}
			word[k]='\0';
			//将刚输入的一个完整的单词与之前输入的单词进行比较 
            for(i=0;i=j && strlen(word)){
				strcpy(words[j],word); 
				count++;
				j++;
			}
            k=0;   
        }
        printf("%d\n",count);
    }
}
2073.无限的路
Problem Description
甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直线,于是他就在平面直角坐标系中画出如下的图形:

甜甜的好朋友蜜蜜发现上面的图还是有点规则的,于是他问甜甜:在你画的图中,我给你两个点,请你算一算连接两点的折线长度(即沿折线走的路线长度)吧。

Input
第一个数是正整数N(≤100)。代表数据的组数。
每组数据由四个非负整数组成x1,y1,x2,y2;所有的数都不会大于100。

Output
对于每组数据,输出两点(x1,y1),(x2,y2)之间的折线距离。注意输出结果精确到小数点后3位。

Sample Input
5
0 0 0 1
0 0 1 0
2 3 3 1
99 99 9 9
5 5 5 5

Sample Output
1.000
2.414
10.646
54985.047
0.000

在这里插入图片描述 分析:找出规律,事先用数组记录结果。

#include 
#include 

void InfiniteRoad(){
	double A[202]={0};
	double s1,s2,dis;
	int i,N,x1,y1,x2,y2; 
	for(i=1;i            
关注
打赏
1665627467
查看更多评论
0.0395s