C ++ algorithms brush title notes

string turn int

string s;
int num;
//将s从第i个切m个字符串
//.c_str()变指针再转int
num = atoi(s.substr(i,m).c_str());

Definition of the structure, sorted Comparative

#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
struct node{
	string t;
	int value;
}; 
bool cmp(const node &a, const node &b){
	return a.value!=b.value ? a.value>b.value:a.t<b.t;
}
int main(){
    vector<node> ans(n);
    sort(ans.begin(), ans.end(), cmp);
    return 0;
}

Reads the input file

freopen("input.txt","r",stdin);

string t

Interception

t.substr (5,10) // subscript taken back 10-bit string 5

printf ( "% s", t.c_str ()); // Print

unordered_map

            unordered_map<string, int> m;
			for(int j=0;j<n;j++){
				if(v[j].t.substr(4,6) == s)
					m[v[j].t.substr(1,3)]++;
			}
			for(auto it : m)
				ans.push_back({it.first, it.second});

 

Published 67 original articles · won praise 14 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_38603360/article/details/103698366