CCF(JSON查询:40分):字符串+模拟
JSON查询
201709-3
纯字符串模拟,考的就是耐心和细心。可惜这两样我都缺。。。
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
const int maxn=102;
int n,m;
string row[maxn];
map<string,string> attr;
int main(){
cin>>n>>m;
getchar();
for(int i=0;i<n;i++){
getline(cin,row[i]);
string temp="";
for(int j=0;j<row[i].length();j++){
if(row[i][j]!=' '){
temp+=row[i][j];
}
}
row[i]=temp;
}
// for(int i=0;i<n;i++)
// cout<<row[i]<<endl;
int times=0;
string temp="";
string pre;
int cnt=0;
for(int i=0;i<n;i++){
bool flag=false;
for(int j=0;j<row[i].length();j++){
if(row[i][j]=='{'&&j==0){
continue;
}else if(row[i][j]=='}'&&j==row[i].length()-1){
continue;
}else if(row[i][j]=='\"'&&!flag&&(j==0||row[i][j-1]!='\\')){
flag=true;
cnt++;
}else if(row[i][j]=='\"'&&flag&&row[i][j-1]!='\\'){
flag=false;
cnt++;
if(times>0){//已经出现过冒号了
attr[pre]=temp;
times=0;
//cout<<pre<<" "<<temp<<endl;
}else{//还没有出现过冒号
pre=temp;
}
//cout<<pre<<" "<<temp<<endl;
temp="";
}else if(row[i][j]==':'){//键和值
if(cnt%2==0){
times++;
temp="";
}else temp+=row[i][j];
}else if(row[i][j]==','){
if(cnt==4){
temp="";
cnt=0;
}else temp+=row[i][j];
}else{
temp+=row[i][j];
}
}
}
for(int i=0;i<m;i++){
string key;
cin>>key;
temp="";
for(int j=0;j<key.length();j++){
if(key[j]=='\\'){
temp+='\\';
}
if(key[j]=='\"'){
temp+='\\';
}
temp+=key[j];
}
//cout<<temp<<endl;
if(!attr.count(temp)){
cout<<"NOTEXIST"<<endl;
}else{
cout<<"STRING ";
string now=attr[temp];
bool flag=false;
for(int j=0;j<now.length();j++){
if(now[j]=='\"'&&now[j-1]=='\\')
flag=false;
if(now[j]=='\\'&&!flag){
flag=true;
continue;
}
if(now[j]=='\\'&&flag)
flag=false;
cout<<now[j];
}
cout<<endl;
}
}
//system("pause");
return 0;
}
CCF(JSON查询:40分):字符串+模拟的更多相关文章
- CCF CSP 201709-3 JSON查询
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201709-3 JSON查询 问题描述 JSON (JavaScript Object Not ...
- CCF 201709-3 JSON查询
CCF 201709-3 JSON查询 试题编号: 201709-3 试题名称: JSON查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 JSON (JavaScript ...
- 未能加载文件或程序集“Newtonsoft.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=30a [问题点数:40分,结帖人u010259408]
未能加载文件或程序集“Newtonsoft.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=30a [问题点数:40分,结帖人u01025 ...
- php查询mysql中的json编码后的字符串内容的方法
问题 mysql里存的是json编码后的字符串,其中中文会被转为unicode码,所以直接查询是查询不到的. mysql里的查询如 like "%\u6211\u662f%" 也是 ...
- CCF-CSP 201709-3 JSON查询 题解
试题编号: 201709-3 试题名称: JSON查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 JSON (JavaScript Object Notation) 是一 ...
- json字符串转换成json对象,json对象转换成字符串,值转换成字符串,字符串转成值
一.json相关概念 json,全称为javascript object notation,是一种轻量级的数据交互格式.采用完全独立于语言的文本格式,是一种理想的数据交换格式. 同时,json是jav ...
- 读“40 分,60 分,90 分”
原文链接: http://mp.weixin.qq.com/s?__biz=MzA5MjYyNzY1OQ==&mid=2650901947&idx=1&sn=89af64d3b ...
- CCF-CSP题解 201709-3 JSON查询
要求写一个小程序完成JSON查询的功能. 查询dfs就好了. 存储JSON对象用图(树)就好,把\(<key[],type,val[]>\)作为节点,然后又是字符串处理了. 其实就是个简化 ...
- net.sf.json.JSONObject处理 "null" 字符串的一些坑
转: net.sf.json.JSONObject处理 "null" 字符串的一些坑 2018年05月02日 16:41:25 大白能 阅读数:7026 版权声明:本文为博主原 ...
随机推荐
- 洛谷P1628合并序列【模板】(Trie+dfs)
很久之前写的题了,当时不知道怎么dfs所以卡了一段时间,^_^ 题解:由于题目给了一大堆字符串,所以首先考虑应该可以建树,之后找到T所在的位置,对T所在的位置dfs就行了 代码: 1 #include ...
- 第三方库:logger,自定义日志封装模块
为了使用方便,二次封装logger. import os import datetime from loguru import logger class Logings: __instance = N ...
- Databricks 第11篇:Spark SQL 查询(行转列、列转行、Lateral View、排序)
本文分享在Azure Databricks中如何实现行转列和列转行. 一,行转列 在分组中,把每个分组中的某一列的数据连接在一起: collect_list:把一个分组中的列合成为数组,数据不去重,格 ...
- Prometheus监控k8s企业级应用
Prometheus架构图 常见的镜像 pod 备注 kube-state-metric 用来收集K8S基本状态信息的监控代理 node-exporter 专门用来收集K8S运算节点基础信息,需要部署 ...
- Kubernets二进制安装(12)之部署Node节点服务的kube-Proxy
kube-proxy是Kubernetes的核心组件,部署在每个Node节点上,它是实现Kubernetes Service的通信与负载均衡机制的重要组件; kube-proxy负责为Pod创建代理服 ...
- 杭电多校HDU 6601 Keen On Everything But Triangle(主席树)题解
题意: 有\(n\)根长度不一的棍子,q次询问,求\([L,R]\)区间的棍子所能组成的周长最长的三角形.棍长\(\in [1, 1e9]\),n\(\in [1, 1e5]\). 思路: 由于不构成 ...
- apt 和 apt-get 之间有什么区别?
使用ubuntu的朋友一定会接触一个命令就是apt-get . 使用该工具安装各种应用程序那叫一个爽. 在 Ubuntu 16.04 发行后,apt使用渐渐频繁起来. 那么,apt-get 与 apt ...
- vue template
vue template <template> <div class="custom-class"> ... </div> </templ ...
- what's the difference amount of pdf, epub, and mobi format
what's the difference amount of pdf, epub, and Mobi format What is the difference between pdf, epub ...
- node os env reader
node os env reader node-os-env-reader.js #!/usr/bin/env node "use strict"; /** * * @author ...