杭电oj2019、2020、2021

2019

#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n,m,i,j;
	long a[100][100];
    while(cin>>n>>m){
	//输入分数 
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
			cin>>a[i][j];
	long max=0;
	int x,y;
	for(i=0;i<m;i++)
		for(j=0;j<n;j++)
		{ if(abs(a[i][j])>abs(max))//max前别忘了加绝对值!! 
		   max=a[i][j];
		   x=i;
		   y=j;
			
		}
	 cout<<++x<<" "<<++y<<" "<<max<<endl;
    }	 	
    return 0;
} 

2020

#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n;
	int a[101];
	while(cin>>n){
		if(n==0)
		break;
		int temp,i,j;
		for(int i=0;i<n;i++){
		   cin>>a[i];	
		}
		//用了绝对值函数abs() 
		for(i=0;i<n-1;i++)
            for(j=i+1;j<n;j++)
                if(abs(a[i])<abs(a[j]))
                {
                    temp=a[i];
                    a[i]=a[j];
                    a[j]=temp;
                }
       for(i=0;i<n;i++){
       	if(i==n-1)
       	 cout<<a[i]<<endl;
       	 else
       	cout<<a[i]<<" ";
       }
	}
}

2021

#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,x;
	//每次从面值大的开始试 
	int a[6] = { 100,50,10,5,2,1 };
	while(cin>>n){
		if(n==0)
		  break;
		  int count=0;
	while(n--){
		cin>>x;
		for(int i=0;i<6;i++){
			if(x>=a[i])
			  {
			  	count+=x/a[i];
				  x=x%a[i];
				  if(x==0)break; 
			  }	
		}
	}
			cout<<count<<endl;	
	}
	return 0;
}
发布了43 篇原创文章 · 获赞 0 · 访问量 595

猜你喜欢

转载自blog.csdn.net/weixin_45191675/article/details/104774168