在XCode的一个项目中创建多个C/C++/Cpp文件并分别运行——创建多个target实现

首先创建一个project:打开XCode并选择Create a new Xcode project

选择macOS-Command Line Tool,点击Next,然后输入project名称,并选择C或C++语言

这个时候已经创建了一个cpp-project的项目,里面包含了一个main.cpp文件。如果这个时候想要在同一个工程里面创建第二个带main函数的c++文件并运行,就需要通过创建Target来实现。

Project是一个工程项目,一个Project可以包含多个Target。Target之间互相没有关系,Target于Project的关系是:Target的Setting一部分继承自Project的Setting。

创建Target,点击File-New-Target…

选择macOS-Command Line Tool-Next,输入Target名称,语言选择C或者C++:

新建了两个Target之后,该project的目录结构如图所示:

当需要运行某个cpp文件时,要在选择target处选择对应的target,然后command+R运行即是运行的当前所选的target中的main.cpp文件:

此文写给某只可爱的猿。

Mac terminal终端或iterm2【 ?~?】~两边出现问号、字体有背景色的问题

主要是mac下oh-my-zsh配置主题的时候字体出了问题

关于字体有背景色问题,打开terminal的偏好设置,点击描述文件(profiles),把“显示ANSI颜色”选项取消即可

关于波浪线两边的两个问号问题,是因为配置中有非ascii字符编码,这两个问号本来是好看的箭头,但是箭头在当前字体中是不会被显示的……所以解决方法是重新下载一个支持非ascii编码的字体:

github上有一个字体:yizhen20133868/fonts

在terminal中执行以下代码:

打开terminal的偏好设置-描述文件,点击字体的“更改…”左上角设置按钮有个“管理字体…”,将刚刚安装的字体导入,然后在更改字体为刚刚导入的那个字体,我选择的是 Meslo LG S DZ Regular for Powerline 字体

然后就愉快的解决了这个问题……不会是问号,而变成箭头了~

1145. Hashing – Average Search Time (25) – 甲级

The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys from the table and output the average search time (the number of comparisons made to find whether or not the key is in the table). The hash function is defined to be “H(key) = key % TSize” where TSize is the maximum size of the hash table. Quadratic probing (with positive increments only) is used to solve the collisions.
Note that the table size is better to be prime. If the maximum size given by the user is not prime, you must re-define the table size to be the smallest prime number which is larger than the size given by the user.
Input Specification:
Each input file contains one test case. For each case, the first line contains two positive numbers: MSize, N, and M, which are the user-defined table size, the number of input numbers, and the number of keys to be found, respectively. All the three numbers are no more than 104. Then N distinct positive integers are given in the next line. All the numbers in a line are separated by a space and are no more than 105.
Output Specification:
For each test case, in case it is impossible to insert some number, print in a line “X cannot be inserted.” where X is the input number. Finally print in a line the average search time for all the M keys, accurate up to 1 decimal place.
Sample Input:
4 5 4
10 6 4 15 11
11 4 15 2
Sample Output:
15 cannot be inserted.
2.8

题目大意:给定一个序列,用平方探测法解决哈希冲突,然后给出m个数字,如果这个数字不能够被插入就输出”X cannot be inserted.”,然后输出这m个数字的平均查找时间
分析:先找到大于tsize的最小的素数为真正的tsize,然后建立一个tsize长度的数组。首先用平方探测法插入数字a,每次pos = (a + j * j) % tsize,j是从0~tsize-1的数字,如果当前位置可以插入就将a赋值给v[pos],如果一次都没有能够插入成功就输出”X cannot be inserted.”。其次计算平均查找时间,一开始cnt=1表示查找一次,每次计算pos = (a + j * j) % tsize,如果v[pos]处正是a则查找到了,所以退出循环,如果v[pos]处不存在数字表示没查找到,那么也要退出循环,最后将cnt累加到ans里表示总的查找时间,最后除以m得到平均查找时间然后输出~

 

PAT 1147. Heaps (30) – 甲级

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to (in a min heap) the key of C. A common implementation of a heap is the binary heap, in which the tree is a complete binary tree. (Quoted from Wikipedia at https://en.wikipedia.org/wiki/Heap_(data_structure))
Your job is to tell if a given complete binary tree is a heap.
Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers: M (<= 100), the number of trees to be tested; and N (1 < N <= 1000), the number of keys in each tree, respectively. Then M lines follow, each contains N distinct integer keys (all in the range of int), which gives the level order traversal sequence of a complete binary tree.
Output Specification:
For each given tree, print in a line “Max Heap” if it is a max heap, or “Min Heap” for a min heap, or “Not Heap” if it is not a heap at all. Then in the next line print the trees postorder traversal sequence. All the numbers are separated by a space, and there must no extra space at the beginning or the end of the line.

Sample Input:
3 8
98 72 86 60 65 12 23 50
8 38 25 58 52 82 70 60
10 28 15 12 34 9 8 56
Sample Output:
Max Heap
50 60 65 72 12 23 86 98
Min Heap
60 58 52 38 82 70 25 8
Not Heap
56 12 34 28 9 8 15 10

题目大意:给一个树的层序遍历,判断它是不是堆,是大顶堆还是小顶堆。输出这个树的后序遍历~
分析:30分大题,28行代码,一行代码一分……((⊙o⊙)嗯) // 我为什么这么机智可爱又伶俐?
首先根据v[0]和v[1]的大小比较判断可能是大顶还是小顶,分别赋值flag为1和-1,先根据层序遍历,从0~(n-1)/2【所有有孩子的结点】判断他们的孩子是不是满足flag的要求,如果有一个结点不满足,那就将flag=0表示这不是一个堆。根据flag输出是否是堆,大顶堆还是小顶堆,然后后序遍历,根据index分别遍历index*2+1和index*2+2,即他们的左右孩子,遍历完左右子树后输出根结点,即完成了后序遍历~