当前位置:   article > 正文

杭电oj简单题 1004、1008、1012、1037、2070、2071_杭电oj1004c语言答案

杭电oj1004c语言答案

1004
气球中颜色最多的是哪个颜色,用map

#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
  map<string,int>ballen;
  int N;
  string str;
  while(cin>>N){
  	if(N==0)
  	 break;
  	 ballen.clear();
  	 while(N--){
  	 	cin>>str;
  	 	ballen[str]++;
  	 }//将颜色 数目键值对输入完毕
	   //下面开始遍历找最大值
	   //因为是牵扯到键和值,所以用迭代器
	   /*int max=0;
	   string maxColor;
	   map<string,int>::iterator iter;
	   for(iter=ballen.begin();iter!=ballen.end();iter++){
	   	if(iter->second>max){
	   		max=iter->second;
	   		maxColor=iter->first;
	   	}
	   } 
	   cout<<maxColor;*/
	   //下面是另一种方法
	    map<string,int>::iterator m,p;
	    p=m=ballen.begin();
	    for(;p!=ballen.end();p++){
	   	if(p->second>m->second)
	   	m=p;//m始终指向最大的值 
	   } 
	   cout<<m->first<<endl;
	    
  }
	return 0;
} 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

1008

#include<iostream>
using namespace std;
int main(){
	int N,j;
	while(cin>>N){
		if(N==0)
		break;
		int i=0;
		int sum=0;
		while(N--){
			cin>>j;
			if(j>i){
				sum+=(j-i)*6;
			}
			else if(j<i){
				sum+=(i-j)*4;
			}
			sum+=5;
			i=j;
		}
		cout<<sum<<endl;
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

1012

#include<iostream>
#include<cstdio>
using namespace std;
int jie(int x){
	int sum=1;
	for(int i=x;i>=1;i--)
	 sum*=i;
	 return sum;
}
int main(){
	int n;
	double a[11];
	cout<<"n e"<<endl;
	cout<<"- -----------"<<endl;
	cout<<"0 1"<<endl;
	cout<<"1 2"<<endl;
	cout<<"2 2.5"<<endl;
	a[0]=1;
	for(int n=1;n<=9;n++){
		a[n]=a[n-1]+1.0/jie(n);
	}
	for(int i=3;i<=9;i++)
	printf("%d %.9lf\n",i,a[i]);
	
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

1037

#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>168&&b>168&&c>168)
	cout<<"NO CRASH"<<endl;
	else if(a<=168)
	 cout<<"CRASH"<<" "<<a<<endl;
	 else if(b<=168)
	 cout<<"CRASH"<<" "<<b<<endl;
	 else
	 cout<<"CRASH"<<" "<<c<<endl;
	
	return 0;
}
/*
int main(){
	int a[3];
	for(int i=0;i<3;i++)
	cin>>a[i];
	int k=1;
	for(int i=0;i<3;i++){
	 if(a[i]<=168){
	   cout<<"CRASH"<<" "<<a[i]<<endl;
	   k=0;
	   break;//别忘了break! 
        }
      if(k)
	    cout<<"NO CRASH"<<endl;
	}
return 0;
}
*/ 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

2070

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int n;
	__int64 a[51];
	while(1){
	cin>>n;
	if(n==-1)
	break;
	a[0]=0;
	a[1]=1;
	for(int i=2;i<=n;i++){
	  a[i]=a[i-1]+a[i-2];	
	}
	cout<<a[n]<<endl;
		
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

2071

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int t,n;
	double high=0.0;
	cin>>t;
	while(t--){
		cin>>n;
		double max=0.0;
		while(n--){
		cin>>high;
		if(high>max)
		max=high;	
		}
		printf("%.2lf\n",max);
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/645543
推荐阅读
相关标签
  

闽ICP备14008679号