ZOJ 3427 Array Slicing (scanf使用)
题意 Watashi发明了一种蛋疼(eggache) 语言 你要为这个语言实现一个 array slicing 函数 这个函数的功能是 有一个数组初始为空 每次给你一个区间[ l, r) 和一些数 你要输出数组中下标在[l,
r) 之间的数 然后删除这些数 然后把给你的那些数插入到数组的下标为 l 的位置
签到模拟题 一直没看懂题意 看了Watashi的scanf高端使用方法 弱到连scanf都不会用了 强行到cpp预习了一下
先记录一下那些并不了解的scanf使用方法吧
int scanf ( const char * format, ... );
- 空白字符: scanf在读入时会忽略下一个非空白字符之前的全部空白字符 空白字符包括 ' ''\t', '\n', '\v', '\f', '\r
- 非%的非空白字符: 输入时必须严格匹配这些字符 否则会读入失败
- 格式说明符%: 说明读取数据的类型或读取规则 %[*][width][length]specifier
int(d) 和 long long(lld)
| specifier | 描写叙述 | Characters extracted |
|---|---|---|
| i | Integer | Any number of digits, optionally preceded by a sign (+ or -). Decimal digits assumed by default (0-9), but a 0 prefix introduces octal digits (0-7), and 0x hexadecimal digits (0-f). Signed argument. |
| d or u |
Decimal integer | Any number of decimal digits (0-9), optionally preceded by a sign (+ or -). d is for a signed argument, and u for an unsigned. |
| o | Octal integer | Any number of octal digits (0-7), optionally preceded by a sign (+ or -). Unsigned argument. |
| x | Hexadecimal integer | Any number of hexadecimal digits (0-9, a-f, A-F), optionally preceded by 0x or 0X, and all optionally preceded by a sign (+ or -). Unsigned argument. |
| f, e, g | Floating point number | A series of decimal digits, optionally containing a decimal point, optionally preceeded by a sign (+ or -) and optionally followed by the e or E character and a decimal integer (or some of the other sequences supported by strtod). Implementations complying with C99 also support hexadecimal floating-point format when preceded by 0x or 0X. |
| a | ||
| c | Character | The next character. If a width other than 1 is specified, the function reads exactly widthcharacters and stores them in the successive locations of the array passed as argument. No null character is appended at the end. |
| s | String of characters | Any number of non-whitespace characters, stopping at the first whitespace character found. A terminating null character is automatically added at the end of the stored sequence. |
| p | Pointer address | A sequence of characters representing a pointer. The particular format used depends on the system and library implementation, but it is the same as the one used to format %p in fprintf. |
| [characters] | Scanset | Any number of the characters specified between the brackets. A dash (-) that is not the first character may produce non-portable behavior in some library implementations. |
| [^characters] | Negated scanset | Any number of characters none of them specified as characters between the brackets. |
| n | Count | No input is consumed. The number of characters read so far from stdin is stored in the pointed location. |
| % | % | A % followed by another % matches a single %. |
int main()
{
char s[500];
int n;
scanf("%s%n", s, &n);
printf("%s %d\n", s, n);
//输入hello
//输出hello 5
return 0;
}
int main()
{
int n;
printf("hello%n", &n);
printf(" %d\n", n);
//输出hello 5
return 0;
}
specifier能够是[...]、[^...]这两种正則表達式
[...]表示读取括号里包括的字符 遇到其它字符就结束这个specifier
int main()
{
char s[500];
int n;
scanf(" %[0-9]%n", s, &n);//%[0-9]仅仅读取数字 遇到非数字结束
printf("%s %d\n", s, n);
scanf(" %[ab]%n", s, &n);
printf("%s %d\n", s, n);
//输入" 12345abc" 前面有三个空格
//输出12345 8 ab 2
return 0;
}
[^...]表示读取除括号里字符之外的全部字符 遇到括号里的字符就结束这个specifier
当然这些东西sscanf也适用
感觉预习了scanf之后这个题的输入就非常优点理了
直接用list的splice函数即可了
#include <bits/stdc++.h>
using namespace std;
char s[5000], *ps; int main()
{
list<int> a, b;
int l, r, n, v;
list<int>::iterator it;
while(~scanf(" [ %d : %d ]%[^\n]", &l, &r, s))
{
b.clear();
ps = s;
while(sscanf(ps, "%*[^-0-9]%d%n", &v, &n) > 0)
{
//过滤掉非'-'和数字再读入一个数
//n记录scanf读了多少个字符
ps = ps + n; //读了n个字符所以要前进n位
b.push_back(v);
} advance(it = a.begin(), l);
while(l < r)
{
printf("%d%s", *it, l < r - 1 ? ", " : "");
it = a.erase(it);
l++;
}
puts("");
a.splice(it, b);
}
return 0;
}
Array Slicing
Time Limit: 2 Seconds Memory Limit: 65536 KB
Array slicing is an operation that extracts certain elements from an array and packages them as another array. Now you're asked to implements the array slicing operations for a new programming
language -- eggache* (pronounced "eggache star"). The grammar of array slicing in eggache* is:
[ begin : end ] = x1, x2, ..., xk, ...
where begin ≤ end are
indices indicating the range of slice. Redundant whitespaces should be ignored. For each operation, the original slice should be printed first, then these elements will be replaced with the new elements provided. See sample for more details.
Input
There is only one case for this problem, which contains about 50 lines of array slicing operations. It's guaranteed that all operations are valid and the absolute values of all integers
never exceed 100. The array is empty ([]) before the first operation.
Output
The output produced by array slicing operations in the eggache* programming language.
Sample Input
[ 0 : 0] = 1 2 3 4 5 6 7 8 9
[ 1 : 1] = -1
[ 1 : 1] =
[ 0 : 8] = 9 8 7 6 5 4 3 2 1
[ 2 : 8] = -2, -3, -5, -7
[ 0 : 9] = 000
[ 0 : 1] = 1, 2, 8
[ 2 : 2] = 4
[ 0 : 4] =
Sample Output
1, -1, 2, 3, 4, 5, 6, 7
7, 6, 5, 4, 3, 2
9, 8, -2, -3, -5, -7, 1, 8, 9
0 1, 2, 4, 8
ZOJ 3427 Array Slicing (scanf使用)的更多相关文章
- [Python Cookbook] Numpy Array Slicing and Indexing
1-D Array Indexing Use bracket notation [ ] to get the value at a specific index. Remember that inde ...
- golang ----array and slice
Go Slices: usage and internals Introduction Go's slice type provides a convenient and efficient mean ...
- C语言范例学习04
第三章 算法 前言:许多人对算法的看法是截然不同的,我之前提到过了.不过,我要说的还是那句话:算法体现编程思想,编程思想指引算法. 同时,有许多人认为简单算法都太简单了,应当去学习一些更为实用的复杂算 ...
- c语言完成分块查找
首先要把一系列数组均匀分成若干块(最后一个可以不均匀) 每块中元素任意排列,即块中数字无序,但是整个块之间要有序.因此也存在局限性. #include<stdio.h> //分块查找法 v ...
- 用c语言编写二分查找法
二分法的适用范围为有序数列,这方面很有局限性. #include<stdio.h> //二分查找法 void binary_search(int a[],int start,int mid ...
- coffeescript 1.8.0 documents
CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque ...
- 《C程序设计的抽象思维》2.10编程练习(未完)
本文地址:http://www.cnblogs.com/archimedes/p/programming-abstractions-in-c-2.html,转载请注明源地址. 2.按照规定求圆柱的表面 ...
- C语言中动态分配数组
如何动态的定义及使用数组呢?记得一般用数组的时候都是先指定大小的.当时问老师,老师说是不可以的.后来又问了一位教C++的老师,他告诉我在C++里用new可以做到,一直不用C++,所以也不明白.今天在逛 ...
- 现代程序设计——homework-01
1.我的GitHub用户 首先,接触到现代程序设计这门课之后我才正式开始使用GitHub和它的客户端,以前都是去网站看代码.扒样例.我注册的账户名为:hennande.目前该账户中有我的第一份关于ho ...
随机推荐
- ASIHTTPRequest的环境配置和使用示例
ASIHTTPRequest类库是基于ISO SDK的一组网络请求的API.IOS SDK的网络组件CFNetwork API操作起来非常复杂.而ASIHTTPRequest类库是对CFNetwork ...
- Eclipse寻找JVM(JRE)的顺序机制
http://developer.51cto.com/art/200907/135271.htm Eclipse也是一个普通的Java程序,因此必须有一个JRE做为运行环境.本文将简单谈谈Eclips ...
- Windows Server 2008 Standard Enterprise Datacenter各个版本区别
-- Windows Server 2008 Standard 包含1个虚拟实例许可,5个客户端访问授权,售价999美元. -- Windows Server 2008 Enterprise 包含4个 ...
- Java对象引用传递探索
一直认为自己对对象传递理解的颇为深刻,没想到最近一次的编码中,就犯下了这样的错误,令自己排查了很久才找到问题的根源, 辅以小case记录以自省. 代码如下: public class ObjRefer ...
- 如何把rc.local里执行的shell脚本的日志内容放到其他位置
rc.local的日志内容默认是/var/log/boot.log /etc/rc.d/rc.local文件的文件头是#!/bin/sh ,我们把这修改成#!/bin/sh -x,这样系统启动后就会把 ...
- ASP.NET MVC Model验证
http://www.wyjexplorer.cn/Post/2012/8/3/model-validation-in-aspnet-mvc3 ASP.NET MVC3中的Model是自验证的,这是通 ...
- 在线分享Oracle尖峰时刻--2014年中秋节尖峰在线福利!
********************************************************** 2014年中秋节尖峰在线福利!*************** ...
- Orchard运用 - 为博客启用Markdown编辑器
有时决定你是否使用某一个博客系统,最看重就是如何更简便的写博客,不能让其成为一个负担或别扭费力不讨好的工作. 对此一个好的编辑器就是一个最靓丽的卖点.比如最新的博客系统ghost.org就只定位一个最 ...
- C#方法中的ref和out
ref 通常我们向方法中传递的是值.方法获得的是这些值的一个拷贝,然后使用这些拷贝,当方法运行完毕后,这些拷贝将被丢弃,而原来的值不将受到影响.此外我们还有其他向方法传递参数的形式,引用 ...
- mysql基础知识之-数据库的创建、查看等常用操作
命令创建mysql数据库: 先启动mysql数据库,连接数据库: mysql -uroot -p123456 (语法:mysql -u登录名 -p密码) 创建表: create dat ...