当前位置: 首页 > news >正文

ZOJ 3427 Array Slicing (scanf使用)

题意  Watashi发明了一种蛋疼(eggache) 语言  你要为这个语言实现一个 array slicing 函数  这个函数的功能是 有一个数组初始为空  每次给你一个区间[ l, r)  和一些数   你要输出数组中下标在[l, r) 之间的数  然后删除这些数  然后把给你的那些数插入到数组的下标为 l 的位置

签到模拟题  一直没看懂题意  看了Watashi的scanf高端使用方法  弱到连scanf都不会用了  强行到cpp预习了一下  先记录一下那些并不了解的scanf使用方法吧

int scanf ( const char * format, ... );

format 由这些内容组成
  • 空白字符: scanf在读入时会忽略下一个非空白字符之前的全部空白字符  空白字符包括 ' ''\t', '\n', '\v', '\f', '\r
  • 非%的非空白字符: 输入时必须严格匹配这些字符  否则会读入失败
  • 格式说明符%: 说明读取数据的类型或读取规则  %[*][width][length]specifier
* 表示这个格式说明符所相应的内容读而不存  也不用为其指定參数  (注意差别 printf  * 须要一个整型參数  表示至少输出多少位 不足用空格取代)
width 表示最多读取多少位字符
length 有的话一定是这几个之中的一个  hh h l ll j z t L  相应同种数据的不同位数类型如 int(d) 和 long long(lld)

重点是 specifier
specifier描写叙述Characters extracted
i      IntegerAny 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 integerAny number of decimal digits (0-9), optionally preceded by a sign (+ or -).
d is for a signed argument, and u for an unsigned.
oOctal integerAny number of octal digits (0-7), optionally preceded by a sign (+ or -).
Unsigned argument.
xHexadecimal integerAny number of hexadecimal digits (0-9a-fA-F), optionally preceded by 0x or 0X, and all optionally preceded by a sign (+ or -).
Unsigned argument.
fegFloating point numberA 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
cCharacterThe 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.
sString of charactersAny 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.
pPointer addressA 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]ScansetAny 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 scansetAny number of characters none of them specified as characters between the brackets.
nCountNo input is consumed.
The number of characters read so far from stdin is stored in the pointed location.
%%% followed by another % matches a single %.

除了 n 之外   specifier至少匹配一个输入的字符  否则读入会在当前字符终止   n须要一个指向int的參数  保存在这之前读取了多少位字符
int main()
{
    char s[500];
    int n;
    scanf("%s%n", s, &n);
    printf("%s  %d\n", s, n);
    //输入hello
    //输出hello 5
    return 0;
}
printf中也能够使用%n表示这条语句这之前输出了多少位字符
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 ] =  x1x2, ...,  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






相关文章:

  • php用正则匹配出图片img标签中的src路径(兼容)
  • OC中的属性和成员变量在.h文件和.m文件的不同
  • 【bzoj】1927 [Sdoi2010]星际竞速
  • Spring Cache无效的问题以及解决办法
  • 北亚案例:oracle数据库误删除数据的恢复方法
  • 安装jdk后出现bash: ./java: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
  • Linux/Unix分配进程ID的方法以及源代码实现
  • 双样本T检验-P-T和T-T检验
  • yaml很好的一个demo
  • statement 、prepareStatement的用法和解释
  • 黑客入侵的常法
  • Myeclipse的默认工作区间怎么恢复提示框?
  • 又拍云刘平阳,理性竞争下的技术品牌提升之道
  • 安装Drush工具 -Centos
  • 服务器篇04-配置apache配置参数
  • 【从零开始安装kubernetes-1.7.3】2.flannel、docker以及Harbor的配置以及作用
  • CSS居中完全指南——构建CSS居中决策树
  • iOS仿今日头条、壁纸应用、筛选分类、三方微博、颜色填充等源码
  • JDK 6和JDK 7中的substring()方法
  • js数组之filter
  • js正则,这点儿就够用了
  • LeetCode18.四数之和 JavaScript
  • Shadow DOM 内部构造及如何构建独立组件
  • webpack项目中使用grunt监听文件变动自动打包编译
  • XML已死 ?
  • 分享一份非常强势的Android面试题
  • 机器学习学习笔记一
  • 蓝海存储开关机注意事项总结
  • 前端攻城师
  • 如何使用 OAuth 2.0 将 LinkedIn 集成入 iOS 应用
  • 体验javascript之美-第五课 匿名函数自执行和闭包是一回事儿吗?
  • 温故知新之javascript面向对象
  • 我从编程教室毕业
  • 一些关于Rust在2019年的思考
  • 因为阿里,他们成了“杭漂”
  • 责任链模式的两种实现
  • 正则与JS中的正则
  • !$boo在php中什么意思,php前戏
  • #我与Java虚拟机的故事#连载19:等我技术变强了,我会去看你的 ​
  • (14)Hive调优——合并小文件
  • (Matalb回归预测)PSO-BP粒子群算法优化BP神经网络的多维回归预测
  • (六)c52学习之旅-独立按键
  • (十)T检验-第一部分
  • (一)基于IDEA的JAVA基础1
  • (转)Mysql的优化设置
  • ***微信公众号支付+微信H5支付+微信扫码支付+小程序支付+APP微信支付解决方案总结...
  • *上位机的定义
  • .NET/C# 阻止屏幕关闭,阻止系统进入睡眠状态
  • .NET基础篇——反射的奥妙
  • .set 数据导入matlab,设置变量导入选项 - MATLAB setvaropts - MathWorks 中国
  • /usr/lib/mysql/plugin权限_给数据库增加密码策略遇到的权限问题
  • @ModelAttribute 注解
  • @property @synthesize @dynamic 及相关属性作用探究
  • @property python知乎_Python3基础之:property
  • [ 常用工具篇 ] AntSword 蚁剑安装及使用详解