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分):字符串+模拟的更多相关文章

  1. CCF CSP 201709-3 JSON查询

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201709-3 JSON查询 问题描述 JSON (JavaScript Object Not ...

  2. CCF 201709-3 JSON查询

    CCF 201709-3 JSON查询 试题编号: 201709-3 试题名称: JSON查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 JSON (JavaScript ...

  3. 未能加载文件或程序集“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 ...

  4. php查询mysql中的json编码后的字符串内容的方法

    问题 mysql里存的是json编码后的字符串,其中中文会被转为unicode码,所以直接查询是查询不到的. mysql里的查询如 like "%\u6211\u662f%" 也是 ...

  5. CCF-CSP 201709-3 JSON查询 题解

    试题编号: 201709-3 试题名称: JSON查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 JSON (JavaScript Object Notation) 是一 ...

  6. json字符串转换成json对象,json对象转换成字符串,值转换成字符串,字符串转成值

    一.json相关概念 json,全称为javascript object notation,是一种轻量级的数据交互格式.采用完全独立于语言的文本格式,是一种理想的数据交换格式. 同时,json是jav ...

  7. 读“40 分,60 分,90 分”

    原文链接: http://mp.weixin.qq.com/s?__biz=MzA5MjYyNzY1OQ==&mid=2650901947&idx=1&sn=89af64d3b ...

  8. CCF-CSP题解 201709-3 JSON查询

    要求写一个小程序完成JSON查询的功能. 查询dfs就好了. 存储JSON对象用图(树)就好,把\(<key[],type,val[]>\)作为节点,然后又是字符串处理了. 其实就是个简化 ...

  9. net.sf.json.JSONObject处理 "null" 字符串的一些坑

    转: net.sf.json.JSONObject处理 "null" 字符串的一些坑 2018年05月02日 16:41:25 大白能 阅读数:7026   版权声明:本文为博主原 ...

随机推荐

  1. hdu 5316 Magician 线段树维护最大值

    题目链接:Magician 题意: 给你一个长度为n的序列v,你需要对这个序列进行m次操作,操作一共有两种,输入格式为 type a b 1.如果type==0,你就需要输出[a,b]区间内的美丽序列 ...

  2. tesseract-ocr的安装及使用pycharm来运行

    1.可以在:http://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-4.00.00dev.exe 下载一个exe文件,然后直接按照提 ...

  3. hdu 6795 Little W and Contest 并查集+排列组合

    题意: t组输入,有n个人,刚开始谁也不认识谁.每一个人有一个权值w[i](1<=w[i]<=2),你要挑选3个互相不认识的人组成一个队,且要保证3个人权值之和大于等于5(也就意味着最少要 ...

  4. Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords (贪心)

    题意:你有\(a\)个树枝和\(b\)个钻石,\(2\)个树枝和\(1\)个钻石能造一个铁铲,\(1\)个树枝和\(2\)个钻石能造一把剑,问最多能造多少铲子和剑. 题解:如果\(a\le b\),若 ...

  5. 错误: 未能完成程序集的安装(hr = 0x8007000b)。探测终止。

     解决方案:VS中"工具"->"选项"->"Web项目"->"对网站和项目使用IIS Express的64位版& ...

  6. 再记一次 应用服务器 CPU 暴高事故分析

    一:背景 1. 前言 大概有2个月没写博客了,不是不想写哈

  7. forEachRemaining()方法的用法

    forEachRemaining()是java1.8新增的Iterator接口中的默认方法对于这个方法,官方文档是这么描述的:Performs the given action for each re ...

  8. OpenCV+Ubuntu+缺少Python.h

    在cmake时粗心了, 要确保有 -D PYTHON_INCLUDE_DIR=/usr/include/python3.5 且该目录下存在Python.h文件. 如果在错误提示中是python2, 那 ...

  9. TypeScript TSConfig All In One

    TypeScript TSConfig All In One tsconfig.json https://www.typescriptlang.org/tsconfig https://www.typ ...

  10. 微信小程序 UI 组件库

    微信小程序 UI 组件库 Vant Weapp 需要注意的是 package.json 和 node_modules 必须在 miniprogram 目录下 $ yarn add @vant/weap ...