返回题解分享
讨论 / 题解分享/ 帖子详情

冶炼金属(编程题) - 题解

代码很简单,我使用结构体封装了一下

#include
using namespace std;

//o->x  V(int)  V个o == x  o 不够V!= x  A ->B  o不累加 V的最大值和最小值
struct botNode
{
    int o = 0;
    int x = 0;
};

struct bot
{
    botNode* arr;
    int size;
};
int main()
{
    int num,max = 0,min = 0,flag = 0;
    cin>>num;
    botNode* p = (botNode*)malloc(sizeof(botNode)* num);
    bot s1;
    s1.arr = p;
    for(int i = 0 ; i < num ;i++)
    {
        cin>>s1.arr[i].o>>s1.arr[i].x;
        s1.size++;
    }
    for(int i = 1 ; i < 10000 ; i++)
    {
    	if((s1.arr[0].o / i) != (s1.arr[0].x))continue;
		for(int j = 0 ; j < num ;j++)
		{
			if((s1.arr[j].o / i) != (s1.arr[j].x))goto next;
		}
		if(!flag)max = min = i;
		flag = 1;
		//printf("%d\n",i);
		if(i > max)max = i;
		next :;
	}
	cout<<min<<' '<<max<<endl;
	return 0;
}
0 回复 0 转发 0 喜欢 3 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!