Cutting an integer means to cut a K digits long integer Z into two integers of (K/2) digits long integers A and B. For example, after cutting Z = 167334, we have A = 167 and B = 334. It is interesting to see that Z can be devided
by the product of A and B, as 167334 / (167 x 334) = 3. Given an integer Z, you are supposed to test if it is such an integer.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (<= 20). Then N lines follow, each gives an integer Z (10<=Z<=231). It is guaranteed that the number of digits of Z is an even number.

Output Specification:

For each case, print a single line "Yes" if it is such a number, or "No" if not.

Sample Input:
3

167334

2333

12345678

Sample Output:
Yes

No

No

题目大意:这道题形式与之前的乙级题反转链表很相似,给出一条链表以及一个整数k,要求将链表节点分为三部分输出:值小于0,值大于等于0小于等于k,值大于k,并且每部分节点的相对顺序不改变。

主要思路:先定义代表节点的结构体,包含地址(add),值(val),下个地址(next),获取输入并将每个节点存在其地址作为索引的数组中,然后从首节点开始遍历整个链表,如果节点值<0,则直接输出;如果<=k,则存入容器vec1中;如果>k,则存入容器vec2中,然后再依次遍历输出vec1和vec2中的节点。输出的时候注意,在第一次输出的时候只需要输出当前地址和节点值,其余时候需要输出两次地址(前一次作为上一个节点的next)和一次值。

#include <cstdio>
#include <vector>
using namespace std;
typedef struct{
int add;
int val;
int next;
}Node;
Node node[100000];
vector<Node> vec1, vec2; int main(void) {
int first, n, k, i;
Node x; scanf("%d%d%d", &first, &n, &k);
for (i = 0; i < n; i++) {
scanf("%d%d%d", &x.add, &x.val, &x.next);
node[x.add] = x; //节点放入其地址作为索引的数组中
} //输出小于 0 的部分
bool is_first = true;
for (i = first; i != -1; i = node[i].next) {
if (node[i].val < 0) {
if (is_first) {
printf("%05d %d ", node[i].add, node[i].val);
is_first = false;
}
else
printf("%05d\n%05d %d ", node[i].add, node[i].add, node[i].val);
}
else if (node[i].val <= k)
vec1.push_back(node[i]);
else
vec2.push_back(node[i]);
} //输出 [0, k] 的部分
for (i = 0; i < vec1.size(); i++) {
if (is_first) {
printf("05d %d ", vec1[i].add, vec1[i].val);
is_first = false;
}
else
printf("%05d\n%05d %d ", vec1[i].add, vec1[i].add, vec1[i].val);
} //输出大于 k 的部分
for (i = 0; i < vec2.size(); i++) {
if (is_first) {
printf("%05d %d ", vec2[i].add, vec2[i].val);
is_first = false;
}
else
printf("%05d\n%05d %d ", vec2[i].add, vec2[i].add, vec2[i].val);
}
printf("-1\n"); return 0;
}

PAT-1133 Splitting A Linked List(链表分解)的更多相关文章

  1. PAT 1133 Splitting A Linked List[链表][简单]

    1133 Splitting A Linked List(25 分) Given a singly linked list, you are supposed to rearrange its ele ...

  2. PAT 1133 Splitting A Linked List

    Given a singly linked list, you are supposed to rearrange its elements so that all the negative valu ...

  3. PAT A1133 Splitting A Linked List (25 分)——链表

    Given a singly linked list, you are supposed to rearrange its elements so that all the negative valu ...

  4. PAT A1133 Splitting A Linked List (25) [链表]

    题目 Given a singly linked list, you are supposed to rearrange its elements so that all the negative v ...

  5. 1133 Splitting A Linked List

    题意:把链表按规则调整,使小于0的先输出,然后输出键值在[0,k]的,最后输出键值大于k的. 思路:利用vector<Node> v,v1,v2,v3.遍历链表,把小于0的push到v1中 ...

  6. PAT1133:Splitting A Linked List

    1133. Splitting A Linked List (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  7. PAT_A1133#Splitting A Linked List

    Source: PAT A1133 Splitting A Linked List (25 分) Description: Given a singly linked list, you are su ...

  8. PAT-1133(Splitting A Linked List)vector的应用+链表+思维

    Splitting A Linked List PAT-1133 本题一开始我是完全按照构建链表的数据结构来模拟的,后来发现可以完全使用两个vector来解决 一个重要的性质就是位置是相对不变的. # ...

  9. PAT 1074 Reversing Linked List[链表][一般]

    1074 Reversing Linked List (25)(25 分) Given a constant K and a singly linked list L, you are suppose ...

随机推荐

  1. Django 内置分页的简单使用

    1, 文档 https://docs.djangoproject.com/en/1.11.1/topics/pagination/ 2,视图 from django.core.paginator im ...

  2. dlopen failed: empty/missing DT_HASH in "libx.so" (built with --hash-style=gnu?)

    崩溃日志内容: java.lang.UnsatisfiedLinkError: dlopen failed: empty/missing DT_HASH in "libxxxx.so&quo ...

  3. Xftp的下载安装,以及如何使用XFtp连接虚拟主机/服务器

    1.下载ftp软件  下载地址: 点我立即下载 2.下载后双击安装  下一步  选择Free for Home/School   然后其他的默认下一步即可 3.打开之前领取的免费一年虚拟主机的网址,登 ...

  4. 谈谈JavaScript中的变量、指针和引用

    1.变量 我们可能产生这样一个疑问:编程语言中的变量到底是什么意思呢? 事实上,当我们定义了一个变量a时,就是在存储器中指定了一组存储单元,并将这组存储单元命名为a.变量a的值实际上描述的是这组存储单 ...

  5. Markdown中希腊字母与代码对应表

    字母 代码 α\alphaα $\alpha$ β\betaβ $\beta$ γ\gammaγ $\gamma$ Γ\GammaΓ $\Gamma$ δ\deltaδ $\delta$ Δ\Delt ...

  6. <学习笔记之 JQuery>

    1. mouseenter   当鼠标指针进入(穿过)元素时,触发事件 var is_enter_help = false; $("#help-div").mouseenter(f ...

  7. 算法——Java实现栈

    栈 定义: 栈是一种先进后出的数据结构,我们把允许插入和删除的一端称为栈顶,另一端称为栈底,不含任何元素的栈称为空栈 栈的java代码实现: 基于数组: import org.junit.jupite ...

  8. Jmeter系列(10)- 阶梯加压线程组Stepping Thread Group详解

    如果你想从头学习Jmeter,可以看看这个系列的文章哦 https://www.cnblogs.com/poloyy/category/1746599.html 前言 Stepping Thread ...

  9. SecureCRT怎么将本级文件上传到CentOS

    进入到想要放文件的路径,不然会默认放在当前路径下: 输入 rz -------------------------------------------------------------------- ...

  10. html之表单元素form

    表单元素form \(都是嵌套input标签来实现,其中type属性选择不同则不同\) \(text:文本内容(输入内容可见)\) \(password:密码(输入内容不可见)\) \(submit: ...