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;
}

最新文章

  1. C# 读取excel日期时获取到数字转换成日期
  2. Safari 快捷键
  3. ISO 基础之 (十二) 文件管理
  4. angular源码分析 摘抄 王大鹏 博客 directive指令及系列
  5. OD调试4--绕过nag窗口
  6. Altera USB Blaster 仿真器(EPM240仿制版
  7. Codeforces Round #290 (Div. 2) C. Fox And Names dfs
  8. c语言指针用法
  9. JDK Linux环境配置
  10. java数组、java.lang.String、java.util.Arrays、java.lang.Object的toString()方法和equals()方法详解
  11. Vijos1523贪吃的九头龙【树形DP】
  12. [补档][COGS 2434]暗之链锁
  13. junit initializationError和找不到或无法加载主类
  14. Mycat 分片规则详解--自然月分片
  15. python网络爬虫与信息提取 学习笔记day3
  16. 剑指Offer——知识点储备-网络基础
  17. Rest API
  18. vue移动端适配
  19. 让Windows Server 2008r2 IIS7.5 ASP.NET 支持10万并发请求
  20. Selenium3详解(基本操作,定位方法)

热门文章

  1. Gym 100796K Profact
  2. Redis全面解析
  3. Django用户注册、登录
  4. Gitlab日常维护(三)之Gitlab的备份、迁移、升级
  5. HEXO版本控制与持续集成
  6. codeforces 1042C Array Product【构造】
  7. Single Round Math sdut3260高精度除以低精度
  8. vue 的 computed 属性在什么时间执行
  9. TypeScript 4.x Tutorials
  10. Chinese Parents Game