- 1 结构体应用在sort自定义的cmp函数中
- 2 输入带有空格和逗号的字符串,并以逗号分割
- 3 unordered_map
# 扑克牌 #includeusing namespace std; struct PKP{ int color; //花色 1~4 int num; //牌的数值 1~13,无大小王 int count; //相同数值牌的数量 }; int num_time[100]; bool cmp(PKP a, PKP b){ if(a.count != b.count) return a.count > b.count; if(a.num != b.num) return a.num < b.num; if(a.color != b.color) return a.color < b.color; } int main(){ int N; PKP pkp[100]; cin>>N; for(int i = 0; i < N; i++){ cin>>pkp[i].color>>pkp[i].num; num_time[pkp[i].num]++; } for(int i = 0; i < N; i++){ pkp[i].count = num_time[pkp[i].num]; } sort(pkp,pkp+N,cmp); for(int i = 0; i < N; i++){ cout< 2 输入带有空格和逗号的字符串,并以逗号分割 输入:zhang san,li si,xiao kai,kui tian
string str; getline(cin, str); //读取整行字符串 stringstream ss(str);//存入流 vector3 unordered_mapstrs; //字符串数组 char del = ',';// 分割符号为, string tmp; // while (getline(ss, tmp, del)) { strs.push_back(tmp); } > map; 赋值方式:
map['V'] = makepair(-1, 1);取值方式:
map['V'].first; //取出-1 map['V'].second; //取出1



