1.题目:

一家水果店出售四种水果,每公斤价格的苹果(代码为a)1.5元,橘子(代码为o)1.4元,香蕉(代码为b)1.48元,菠萝(代码为p)1.08元。编一个程序,使售货员只要在键盘上打入货品的代码及重量,计算机将显示货品名、单价、重量及总价。

输入:

4
a 10
o 10
b 10
p 10
2
a 5.7
a 3.8

输出:

       apple  orange banana pineapple sum
price  15.00  14.00  14.80  10.80     54.60  
weight 10.00  10.00  10.00  10.00     40.00  

       apple  orange banana pineapple sum
price  14.25  0.00   0.00   0.00      14.25  
weight 9.50   0.00   0.00   0.00      9.50   
个人心得:

1.此题最大的难点在于输出的格式,我们可以利用动态数组将所有的菜价放入其中,并让最后的一个位置存放总价,最后在依次输出

2.注意计算过程,输入字符相等时对应水果的数量才会变化

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
	int n;
	int first = 1;
	while (scanf("%d", &n) != EOF) {
		vector<double> vec1(5,0.0);
		vector<double> vec2(5,0.0);
		for (int i = 0; i < n; ++i) {
			char d;
			double g;
			scanf(" %c %lf", &d, &g);
			if (d == 'a') {
				vec1[0] = vec1[0] + g;
				vec2[0] = vec2[0] + g * 1.5;
			}
			if (d == 'o') {
				vec1[1] = vec1[1] + g;
				vec2[1] = vec2[1] + g * 1.4;
			}
			if (d == 'b') {
				vec1[2] = vec1[2] + g;
				vec2[2] = vec2[2] + g * 1.48;
			}
			if (d == 'p') {
				vec1[3] = vec1[3] + g;
				vec2[3] = vec2[3] + g * 1.08;
			}
		}
		for (int i = 0; i <= 3; i++) {
			vec1[4] += vec1[i];
			vec2[4] += vec2[i];
		}
		if (first != 1) {
			printf("\n");
		}
		first = 0;
		printf("       apple  orange banana pineapple sum\n");

		printf("price  ");
		printf("%-7.2f", vec2[0]);
		printf("%-7.2f", vec2[1]);
		printf("%-7.2f", vec2[2]);
		printf("%-10.2f", vec2[3]);
		printf("%-7.2f\n", vec2[4]);

		printf("weight ");
		printf("%-7.2f", vec1[0]);
		printf("%-7.2f", vec1[1]);
		printf("%-7.2f", vec1[2]);
		printf("%-10.2f", vec1[3]);
		printf("%-7.2f\n", vec1[4]);

	}
}

2.题目:

给你n个整数,求他们中所有奇数的乘积。

输入:


3 0 4 6 5

输出:15

个人心得:

1.此题在于利用x%2是否等于零进行判断次数是否为奇数

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
	int n;
	int sum = 1;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		int x;
		scanf("%d", &x);
		if (x % 2 != 0) {
			sum *= x;
		}
	}
	printf("%d\n", sum);
}

3.题目:

输入N个日期,每个以年、月、日的顺序读入,打印输出最晚的日期、最早的日期。

输入:

3
2015 3 2
2011 4 15
1 1 1

输出:

2015 3 2
1 1 1
个人心得:

此题容易的情况是当输入的年份都不相等时我们可以根据年份大小进行选择最大,最小,但是一旦当有相同年份的时间出现时,我们就要在年份的基础上再判断月份的大小,如果月份大小也一样,我们就要再看日的大小来判断谁大谁小

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	int maxyear = 0, maxmonth = 0, maxday = 0;
	int minyear = 2016, minmonth = 13, minday = 32;
	for (int i = 1; i <= n; ++i) {
		int curyear, curmonth, curday;
		scanf("%d %d %d", &curyear, &curmonth, &curday);
		if (curyear > maxyear) {
			maxyear = curyear;
			maxmonth = curmonth;
			maxday = curday;
		}
		else if (curyear == maxyear) {
			if (curmonth > maxyear) {
				maxmonth = curmonth;
				maxday = curday;
			}
			else if (curmonth == maxmonth) {
				if (curday > maxday) {
					maxday = curday;
				}
			}
		}
		if (curyear < minyear) {
			minyear = curyear;
			minmonth = curmonth;
			minday = curday;
		}
		else if (curyear == minyear) {
			if (curmonth < minmonth) {
				minmonth = curmonth;
				minday = curday;
			}
			else if (curmonth == minmonth) {
				if (curday < minday) {
					minday = curday;
				}
			}
		}
	}
	printf("%d %d %d\n", maxyear, maxmonth, maxday);
	printf("%d %d %d\n", minyear, minmonth, minday);
	return 0;
}

第一段:

In some cases an agent’s responses improve over time as the agent learns. This could take the form of developing procedural knowledge (learning “how”) or storing declarative knowledge (learning “what”). Learning procedural knowledge usually involves a trial-and-error process by which an agent learns appropriate actions by being punished for poor actions and rewarded for good ones. Following this approach, agents have been developed that, over time, improve their abilities in competitive games such as checkers and chess. Learning declarative knowledge usually takes the form of expanding or altering the "facts" in an agent’s store of knowledge. For example, a baseball player must repeatedly adjust his or her database of knowledge from which rational responses to future events are determined.

翻译:

在某些情况下,随着智能体的不断学习,他的反应也会随着时间推移得到提升,这可能表现为发展程序的知识(学习如何做),或者存储陈述性的知识(学习是什么)。学习程序性的知识通常包括一个试错的过程,在这个过程中,智能体学习合适的行动方式,通过对错误行为的处罚和对正确行为的奖励。通过这种方式,智能体逐渐发展,随着时间的推移,提升他们在富有竞争性的游戏之中的能力,比如跳棋和国际象棋。学习陈述性的知识通常表现为扩展或修改智能体知识库中所存储的事实。列如,一名棒球运动员必须不断调整自己的知识数据库,从中决定对未来事件的理性反应。

第二段:

To produce rational responses to stimuli, an agent must "understand" the stimuli received by its sensors. That is, an agent must be able to extract information from the data produced by its sensors, or in other words, an agent must be able to perceive. In some cases this is a straightforward process. Signals obtained from a gyroscope are easily encoded in forms compatible with calculations for determining responses. But in other cases extracting information from input data is difficult. Examples include understanding speech and images. Likewise, agents must be able to formulate their responses in terms compatible with their actuators. This might be a straightforward process or it might require an agent to formulate responses as complete spoken sentences—meaning that the agent must generate speech. In turn, such topics as image processing and analysis, natural language understanding, and speech generation are important areas of research.

翻译:

为了对刺激产生理性的反应,智能体必须“理解”其传感器接收到的刺激。也就是说,智能体必须能够从传感器产生的数据中提取信息,换句话说,智能体必须具备感知能力。在某些情况下,这个过程是比较直接的。例如,从陀螺仪获得的信号可以很容易地编码成适合用于计算和确定响应的形式。但在其他情况下,从输入数据中提取信息就比较困难,比如理解语音和图像。同样,智能体也必须能够以与其执行器相兼容的方式来形成响应。这有时是一个简单的过程,但有时可能需要智能体将响应组织成完整的口语句子,也就是说,智能体必须生成语音。因此,图像处理与分析、自然语言理解以及语音生成等方向,都是重要的研究领域。

第三段:

The agent attributes that we have identified here represent past as well as current areas of research. Of course, they are not totally independent of each other. We would like to develop agents that possess all of them, producing agents that understand the data received from their environments and develop new response patterns through a learning process whose goal is to maximize the agent’s abilities. However, by isolating various types of rational behavior and pursuing them independently, researchers gain a toehold that can later be combined with progress in other areas to produce more intelligent agents.

翻译:

我们在这里所提到的智能体属性,既包括过去的研究方向,也包括当前的研究方向。当然,这些属性并不是彼此完全独立的。我们希望开发出同时具备这些属性的智能体,使其能够理解从环境中接收到的数据,并通过学习过程形成新的响应模式,而这个学习过程的目标是最大化智能体的能力。不过,通过将不同类型的理性行为分开研究并分别推进,研究人员可以先取得突破点,之后再把各个领域的进展结合起来,从而产生更加智能的智能体。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐