CCF CSP 201709-3 JSON查询
来源:互联网 发布:uujuly淘宝女装店 编辑:程序博客网 时间:2024/05/16 05:30
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>using namespace std;#define ll long longmap<string,string> json;bool iskey;string substring(string last,string str){ if(str.empty()){ return last; } int len = str.size(); for(int i=0;i<len;i++){ if(str[i]==' ') continue ; if(str[i]=='{'){ json[last] = "OBJECT"; iskey = true; }else if(str[i]=='}'){ int l = last.size(); int j; for(j=l-1;l>=0;j--) if(last[j]=='.') break ; if(j<0) last = ""; else last = last.substr(0,j); }else if(str[i]==','){ iskey = true ; }else if(str[i]==':'){ iskey = false ; }else if(str[i]=='"'){ string now ; bool flag = false ; int j; for(j=i+1;j<len;j++){ // “\”hello\”” 处理该种情况 if(str[j]=='\\'){ if(flag){ now += '\\'; flag = false; }else{ flag = true ; } }else if(str[j]=='"'){ if(flag){ now += '"'; flag = false; }else{ break ; } }else{ now += str[j]; } } cout<<now<<endl; i=j; if(iskey){ if(last.empty()){ last = now; }else{ last += '.'+now; } }else{ json[last] = "STRING "+now; int l = last.size(); int g; for(g=l-1;g>=0;g--) if(last[g]=='.') break ; if(g<0)//当没有 。 时说明 是字符串 ,所以需要清空关键值 last = ""; else last = last.substr(0,g); } } } return last;}int main(){ int n,m; ios::sync_with_stdio(false); while(cin>>n>>m){ json.clear(); iskey = true ; string tmp,last=""; getline(cin,tmp);//接受换行 for(int i=0;i<n;i++){ getline(cin,tmp); last = substring(last,tmp); } // map<string,string>::iterator it ;// for(it=json.begin();it!=json.end();it++){ // cout<<it->first<<"--"<<it->second<<endl; // }//上方为数据处理 for(int i=0;i<m;i++){ getline(cin,tmp); if(json[tmp]==""){ cout<<"NOTEXIST"<<endl; }else{ cout<<json[tmp]<<endl; } }//查询阶段 } return 0;}
阅读全文
0 0
- CCF CSP 201709-3 JSON查询
- ccf csp JSON查询
- CCF CSP真题——201709-3 json查询
- 201709-3 JSON查询 ccf
- ccf 201709-3 JSON查询
- CCF 201709-3 JSON查询
- [CCF-CSP]201612-3(权限查询)
- CCF-CSP 权限查询 JAVA 201612-3
- CCF CSP试题 201612-3 权限查询
- CCF CSP 权限查询 JAVA 201612-3
- CCF 201709-3Json查询 Java
- CCF CSP 201612-3 权限查询(Java-100分)
- ccf-csp
- ccf-csp
- CCF JSON查询
- CCF CSP 编程题目和解答-----试题名称:权限查询-------201612-3
- 201709CCF/CSP考试失败内心
- CCF CSP 201709-1 打酱油
- SMO算法伪代码
- Eclipse中使用Hibernate
- 【Java基础总结】-类和对象的易错点
- 深入理解javascript中的立即执行函数(function(){…})()
- 计算机网络—运输层—UDP
- CCF CSP 201709-3 JSON查询
- .Net Micro Framework 快速入门
- mysql主从复制配置实现及其监控与维护
- tomcat集群会话保持
- 机器学习评估方法——P值校验
- 深度机器学习中的batch
- missing artifact com.oracle:ojdbc14:jar:10.2.0.2.0解决办法
- 七牛云存储域名配置
- 文件上传三种方式