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. html+css的用户注册界面

    注册界面样图 代码实现 html部分 <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  2. Redis介绍及字符串操作

    一.前言 不同程序之间实现通信的方法? A.通过不同程序之间建立socket,实现通信.实际应用适用于使用broker,如RabbitMQ,ZeroMQ. B.通过Json,Pickle,利用文件的写 ...

  3. 使用react脚手架create-react-app创建react应用

    Create React App是一种官方支持的创建单页React应用程序的方法.它提供了一个没有配置的现代构建设置. 一.全局安装脚手架: npm install -g create-react-a ...

  4. 新手上路:Laravel-控制器基础

    1.控制器在哪 Controller目录默认存放于app\Htpp\Controllers下,当然,你可以自定义这个目录: Controllers文件夹有一个控制器基类Controller.php,你 ...

  5. Mobile Communication

    最近面试有被问到LTE,感觉说得不太清楚,重新整理一遍. 一.第一代移动通信系统 1G,诞生于1980年左右.模拟通信系统,抗干扰性能差,使用FDMA技术,主要用来传输话音信号,最拉风的就是" ...

  6. 白话typescript中的【extends】和【infer】(含vue3的UnwrapRef)

    大家好,我是小雨小雨,致力于分享有趣的.实用的技术文章. 内容分为翻译和原创,如果有问题,欢迎随时评论或私信,希望和大家一起进步. 分享不易,希望能够得到大家的支持和关注. extends types ...

  7. python selenium(常用关键字)

    1.文本按钮操作相关: send_keys()输入文本 from selenium import webdriver import time dr = webdriver.Chrome() dr.ge ...

  8. Redis集群搭建的三种方式

    一.Redis主从 1.1 Redis主从原理 和MySQL需要主从复制的原因一样,Redis虽然读取写入的速度都特别快,但是也会产生性能瓶颈,特别是在读压力上,为了分担压力,Redis支持主从复制. ...

  9. springboot设置过滤器、监听器、拦截器

    其实这篇文章算不上是springboot的东西,我们在spring普通项目中也是可以直接使用的 设置过滤器: 以前在普通项目中我们要在web.xml中进行filter的配置,但是只从servlet 3 ...

  10. VM虚拟机手动配置IP地址

    1.查看虚拟机的网关 编辑-->虚拟网络编辑器 VMnet8 NAT模式-->NAT设置-->网关IP 2.设置IP地址 系统-->首选项-->网络连接 system e ...