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 3537 Daizhenyang's Coin 翻硬币博弈

    题意: 给你n个硬币,你可以从中拿出来1.2.3个硬币,它们不一定要连续,你只需要保证拿出来的硬币中那个下标最大的硬币一定要是正面朝上,最后谁不能操作,谁就输了 题解: 翻硬币游戏 结论: 局面的SG ...

  2. tomacat服务器上web资源访问流程、web应用打成war包发布、Context的reloadable属性、tomacat体系架构

    一.web资源访问流程 二.web应用打成war包发布到服务器 好处:打成war包发布到服务器,那么服务器会自动把它拆解成文件夹 jar命令是java自带的一个命令,如果之前配置过Java编译环境就可 ...

  3. Atcoder Beginner Contest 168 D - .. (Double Dots) (BFS)

    题意:有\(n\)个房间,在这些房间中两两连\(m\)次条边,问除了第一个房间,其他房间走到第一个房间的最短路径,输出这个房间所连的上一个房间,如果走不到,输出\(no\). 题解:刚开始我写了一个d ...

  4. Hyper-V安装CentOS修改分辨率

    grubby --update-kernel=ALL --args="video=hyperv_fb:1600x900" reboot https://blog.csdn.net/ ...

  5. 正则指引 pdf 高清版

    链接:https://pan.baidu.com/s/1Xeuma4toE_L-MxROvTGBxw 提取码:nqyj

  6. java调用http接口的几种方式总结

    本文参考: https://blog.csdn.net/fightingXia/article/details/71775516 https://www.cnblogs.com/jeffen/p/69 ...

  7. Leetcode(32)-最长有效括号

    给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度. 示例 1: 输入: "(()" 输出: 2 解释: 最长有效括号子串为 "()&quo ...

  8. Github markdown页面内跳转

    基本操作: 请看这里 最典型的就是[alt_content](#jump) 但有时, jump是不太好直接看出来的, 比如下面这个标题, 格式复杂, 那如何获取相应的jump呢? 在Github中, ...

  9. js regular expression & email checker

    js regular expression & email checker const isValidEmail = (email = ``) => /^([\w+\.])+@(\w+) ...

  10. Sketch & UI & PS

    Sketch & UI & PS app ui https://sketchapp.com/learn https://www.sketch.com/docs/ https://ske ...