csu1113模拟,STL
来源:互联网 发布:欧特克软件价格 编辑:程序博客网 时间:2024/06/08 06:45
题目链接:点击打开链接
求增加减少改变的字典词
#include <iostream>#include <stdio.h>#include<cmath>#include <map>#include<string>#include<algorithm>#include<vector>using namespace std;string old,newdic;string midkey,midvalue;char prim[3]= {'+','-','*'};struct node{ string key,val; int flag=0;} str[1005];vector<string> print0,print1,print2;int main(){ int n,i,j; cin>>n; while(n--) {print0.clear();print1.clear();print2.clear(); cin>>old; cin>>newdic; if(!newdic.empty()) newdic.erase(0,1);//去{ int sum=0; while(!newdic.empty())//找到新字典的key,value的对应关系存到str数组里 { midkey.clear(); i=0; if(newdic[i]=='}')break; while(newdic[i]!=':') { midkey.push_back(newdic[i]); i++; } newdic.erase(0,i+1); midvalue.clear(); i=0; while(newdic[i]!=','&&newdic[i]!='}') { midvalue.push_back(newdic[i]); i++; } newdic.erase(0,i+1); str[sum].key=midkey; str[sum].val=midvalue; str[sum].flag=0; sum++; } if(!old.empty())old.erase(0,1);//找到旧字典的key,value的对应关系存到str数组里 while(!old.empty()) { midkey.clear(); i=0; if(old[i]=='}')break; while(old[i]!=':') { midkey.push_back(old[i]); i++; } old.erase(0,i+1); midvalue.clear(); i=0; while(old[i]!=','&&old[i]!='}') { midvalue.push_back(old[i]); i++; } old.erase(0,i+1); int flag=1; for(int j=0; j<sum; j++) { if(midkey==str[j].key) { if(midvalue!=str[j].val) { print2.push_back(midkey);//val值改变了 } str[j].flag=1; flag=0; break; } } if(flag==1) print1.push_back(midkey);//减少de } for(int j=0; j<sum; j++) { if(str[j].flag==0) print0.push_back(str[j].key);//增加的 } if(print0.empty()&&print1.empty()&&print2.empty()) { cout<<"No changes"<<endl; if(n!=0)cout<<endl; continue; } int lens0=print0.size(); int lens1=print1.size(); int lens2=print2.size(); sort(print1.begin(),print1.end()); sort(print0.begin(),print0.end()); sort(print2.begin(),print2.end()); if(!print0.empty()) { cout<<"+"; for( j=0; j<print0.size()-1; j++) { cout<<print0[j]<<","; } cout<<print0[j]<<endl; } if(!print1.empty()) { cout<<"-"; for( j=0; j<print1.size()-1; j++) { cout<<print1[j]<<","; } cout<<print1[j]<<endl; } if(!print2.empty()) { cout<<"*"; for( j=0; j<print2.size()-1; j++) { cout<<print2[j]<<","; } cout<<print2[j]<<endl; } if(n!=0)cout<<endl; } return 0;}
上面这个是去年写的,刚刚用map写了一下,map是按key排序的,所以就不用排序了
#include<iostream>#include<vector>#include<map>#include<algorithm>using namespace std;const int maxn=1e3+10;void work(string &s,map<string,string>&m){ string s1,s2; int i=1; int len=s.size(); if(s[0]=='{'&&s[1]=='}')return;//判断字典是不是空集 while(i<len) { s1.clear(); for(; s[i]!=':'; i++) s1.push_back(s[i]); s2.clear(); for(i++; s[i]!=','&&s[i]!='}'; i++) s2.push_back(s[i]); i++; m[s1]=s2; }}int main(){ int T,i,j; string oldd,newd; cin>>T; while(T--) { map<string,string>m1,m2; vector<string>add,de,change; m1.clear(); m2.clear(); cin>>oldd; work(oldd,m1); cin>>newd; work(newd,m2); add.clear(); de.clear(); change.clear(); map<string,string>:: iterator it1,it2; it1=m1.begin(); it2=m2.begin(); while(it1!=m1.end()&&it2!=m2.end()) { if(it1->first==it2->first) { if(it1->second!=it2->second) change.push_back(it1->first); it1++,it2++; } else if(it1->first<it2->first) { de.push_back(it1->first); it1++; } else { add.push_back(it2->first); it2++; } } while(it1!=m1.end())de.push_back(it1->first),it1++; while(it2!=m2.end())add.push_back(it2->first),it2++; if(add.size()==0&&de.size()==0&&change.size()==0) cout<<"No changes"<<endl; else { if(add.size()!=0) { sort(add.begin(),add.end()); cout<<"+"; for(i=0; i<add.size()-1; i++) cout<<add[i]<<","; cout<<add[i]<<endl; } if(de.size()!=0) { sort(de.begin(),de.end()); cout<<"-"; for(i=0; i<de.size()-1; i++) cout<<de[i]<<","; cout<<de[i]<<endl; } if(change.size()!=0) { cout<<"*"; sort(change.begin(),change.end()); for(i=0; i<change.size()-1; i++) cout<<change[i]<<","; cout<<change[i]<<endl; } } cout<<endl; }}
阅读全文
0 0
- csu1113模拟,STL
- CSU1113——Updating a Dictionary(STL)
- Super_Stack STL模拟栈
- hdu3347(模拟+STL)
- uva 11995 STL模拟
- hdu1702 STL的模拟,
- hdu4302(模拟+STL)
- 【STL】 vector 模拟实现
- <STL>模拟实现List
- <STL>模拟实现Vector
- STL-模拟实现List
- 【STL】模拟实现vector
- 【STL】模拟实现list
- 模拟实现STL-Vector
- URL (STL模拟)
- STL模拟实现vector
- STL模拟实现迭代器
- uva1595对称轴 STL模拟
- Ubuntu上由于/boot容量不足无法更新系统
- 170821 制作UEFI模式Ubuntu启动U盘
- 最长上升子序列
- C#winform只能输入数字后不能复制粘贴问题
- VS一些常见问题处理(收集ing)
- csu1113模拟,STL
- java里绝对路径和相对路径的区别
- sequence list 线性表
- C语言结构体位段特性实现断言宏
- lower_bound以及upper_bound
- C 复习第一课 各个基础类型保存 以及表达式中一些表达方式
- python_装饰器二(对有/不定长参数函数的装饰)
- Java并发编程:同步容器
- SpringBoot21-springboot的数据访问-引入Docker