(体会不同的编程思想的效率差异)A and B and Compilation Errors (看完题先思考如何解决更好)

本文介绍了一种高效算法,通过对比三次编译错误的集合,确定被修复的具体错误编号。利用求和的方法避免了逐个元素对比带来的性能瓶颈。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A and B are preparing themselves for programming contests.

B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.

Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.

However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.

Can you help B find out exactly what two errors he corrected?

Input

The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.

The third line contains n - 1 space-separated integers b1, b2, ..., bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.

The fourth line contains n - 2 space-separated integers с1, с2, ..., сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.

Output

Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.

Example
Input
5
1 5 8 123 7
123 7 5 1
5 1 7
Output
8
123
Input
6
1 4 3 3 5 7
3 7 5 4 3
4 3 7 5
Output
1
3
Note

In the first test sample B first corrects the error number 8, then the error number 123.

In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.

题目的大意是:
给你三组数据,要你每次判断出比上一次减少了哪个数。

#include<iostream>
using namespace std;

int main()
{
	int n;
	while(cin>>n)
	{
		int i;
		int sum_1=0,sum_2=0;
		int T;
		for(i=0;i<n;i++)
		{
			cin>>T;
			sum_1+=T;
		}
		int j;
		int n1=n-1;
		for(j=0;j<2;j++)
		{
			for(i=0;i<n1;i++)
			{
				cin>>T;
				sum_2+=T;
			}
		cout<<sum_1-sum_2<<endl;
		sum_1=sum_2;
		sum_2=0;
		n1--;
		}
		
	}
	return 0;
}
直接用和减和,比一个数一个数的比较效率高太多了,用一个数一个数比较的方法会超秒。
<think>嗯,用户问的是“function created with compilation errors”,也就是在编译过程中出现错误的函数。首,我需要理解这个问的常见原因。可能用户是在编程的时候遇到了编译错误,特别是在定义函数的时候。那么,编译错误通常有哪些原因呢? 首想到的是语法错误,比如缺少括号、分号或者拼写错误。比如在C语言里,函数声明如果漏了花括号或者分号,编译器就会报错。然后是类型不匹配,比如函数声明的返回类型和实际返回的值类型不一致,或者参数类型不匹配。例如,声明了一个返回int的函数,但实际返回了字符串。 还有作用域的问,比如在函数内部使用了未声明的变量,或者变量名拼写错误。此外,函数重名也可能导致冲突,尤其是在大型项目中,如果函数名重复,编译器无法确定该用哪个,就会报错。 另外,有些语言需要函数在使用前声明,如果函数调用在定义之前,而编译器没有看到原型声明,也会出错。比如C语言中,如果函数定义在调用之后,而没有前置声明,就会报编译错误。 还有链接错误,比如函数声明了但没有实现,或者实现的时候参数列表不一致,导致链接器找不到对应的函数定义,这可能在编译阶段或链接阶段报错,具体看语言和编译器。 用户可能需要具体的例子来理解这些错误。比如举一个缺少分号的例子,或者参数类型不匹配的情况。同时,解决方法是检查语法,仔细核对函数声明和定义的每个部分,使用编译器的报错信息定位问所在的行和具体原因。 另外,可能用户对编译错误的信息不太熟悉,不知道如何根据错误信息排查问。这时候需要解释如何阅读错误信息,比如错误类型、行号、提示信息等,这些都是解决的关键线索。 总结下来,回答的结构应该解释编译错误的原因,然后分点列出常见错误类型,给出例子,最后提供解决方法和建议。确保用户能够一步步排查问,理解错误来源,并学会如何避免和修复。</think>在编程中,“function created with compilation errors”表示在编译阶段因代码错误导致函数无法正常通过编译。以下是逐步分析及常见原因: --- ### 一、什么是编译错误? 编译错误(Compilation Errors)是编译器在解析代码时发现的语法或语义问。当函数存在此类错误时,编译器会拒绝生成可执行文件。 --- ### 二、常见错误类型及示例 #### 1. **语法错误** - **缺失符号**:如缺少分号 `;`、括号 `()` 或花括号 `{}`。 ```c int add(int a, int b) { return a + b // 错误:缺少分号 } ``` - **拼写错误**:如关键字拼写错误(`funciton` 代替 `function`)。 #### 2. **类型不匹配** - **返回值类型不符**: ```c int divide(int a, int b) { return a / b; // 正确 } float divide(int a, int b) { // 错误:与已存在函数冲突 return (float)a / b; } ``` - **参数类型错误**: ```java void print(String message) { ... } print(123); // 错误:参数应为字符串 ``` #### 3. **作用域问** - **未声明变量**: ```python def calculate(): result = x + 5 # 错误:x 未定义 ``` #### 4. **重复定义** - **同名函数冲突**: ```c++ void log() { ... } void log() { ... } // 错误:函数重复定义 ``` #### 5. **未实现声明** - **声明未定义**: ```c void myFunction(); // 函数声明 int main() { myFunction(); // 错误:未实现具体定义 } ``` --- ### 三、解决方法 1. **阅读错误信息** 编译器会提示错误类型和位置(如行号)。例如: ``` error: expected ';' before '}' token ``` 2. **逐行检查代码** 检查符号闭合、拼写和语法结构。 3. **隔离测试** 注释掉部分代码,逐步定位问。 4. **工具辅助** 使用 IDE 的语法高亮和实时检查功能(如 VS Code、IntelliJ)。 --- ### 四、示例修复 **错误代码**: ```c #include <stdio.h> int main() { printf("Hello World") return 0; } ``` **错误分析**:`printf` 后缺少分号 `;`。 **修复后**: ```c #include <stdio.h> int main() { printf("Hello World"); // 添加分号 return 0; } ``` --- ### 五、总结 编译错误通常由语法、类型或作用域问引起。通过仔细阅读错误信息、检查代码逻辑,并结合工具辅助,可高效定位并解决
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值