不一样的烟火

//多项式求和
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double n,m;
	cin>>n>>m;
	double a[30009];
	for(int i=0;i<n+1;i++){
		cin>>a[i];
	}
	double x=a[0];
	for(int i=1;i<n+1;i++){
		x=a[i]+x*m;
	}
	printf("%.3lf",x);
	return 0;
}

//最大子列和问题
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,sum=0;
	cin>>n;
	int a,max=0;
	for(int i=0;i<n;i++){
		cin>>a;
		sum+=a;
		if(sum>max) max=sum;
		else
		if(sum<0) sum=0;
	}
	cout<<max<<endl;
	return 0;
}

//两个有序序列的中位数
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,y;
	cin>>n;
	vector<int>v;
	for(int i=0;i<n;i++){
		cin>>x;
		v.push_back(x);
	}
	for(int i=0;i<n;i++){
		cin>>y;
		v.push_back(y);
	}
	sort(v.begin(),v.end());
	cout<<v[n-1];
	return 0;
}

//数组循环左移
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=m;i<n+m;i++){
		cout<<a[i%n];
		if(i!=n+m-1)
		cout<<" ";
	}
	return 0;
}

//数列求和-加强版
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	if(m==0){
		cout<<"0";
		return 0;
	}
	int j=0,k=0,h1,h;
	char a[1000001];
	while(m>0){
		h=n*m;
		h1=(h+j)%10;
		a[k++]=h1+'0';
		j=(h+j)/10;
		m--;
	}
	if(j>0){
		a[k++]=j+'0';
		a[k]='\0';
	}
	else a[k]='\0';
	for(int i=k-1;i>=0;i--)
	cout<<a[i];
	return 0;
}

//一元多项式求导
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,a,b;
	int f=0;
	while(cin>>x>>y){
		a=x*y;
		b=y-1;
		if(y>0){
			if(f==0){
		cout<<a<<" "<<b;
		f=1;	
		}
		else cout<<" "<<a<<" "<<b;
		}
	}
	if(f==0) cout<<"0"<<" "<<"0";
	return 0;
}

//顺序表的建立及遍历
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,f;
	cin>>n;
	int a[n];
	f=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(f==0){
		cout<<a[i];
		f=1;	
		}
		else cout<<" "<<a[i];
	}
	return 0;
}

//最长连续递增子序列
#include<bits/stdc++.h>
using namespace std;
//const int N=1e5+5;
int main()
{
	int n,k=0,max=0,p=0;
	cin>>n;
	int a[100000];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++){
		if(a[i+1]>a[i]) k++;
		else{
			if(k>max){
				max=k;
				p=i;
			}
		k=0;
		}
	}
	for(int i=p-max;i<=p;i++){
	cout<<a[i];
	if(i!=p) cout<<" ";
	}
	return 0;
}

//堆栈操作合法性 
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
	int n,m;
	cin>>n>>m;
	string s;
	int sum;
	getchar();
	for(int i=0;i<n;i++){
		//getchar();
		sum=0;
		getline(cin,s);
		for(int i=0;i<s.size();i++){
			if(s[i]=='S') sum=sum+1;
			if(s[i]=='X') sum=sum-1;
			if(sum<0||sum>m) break;
		}
		if(sum==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

//银行业务队列简单模拟
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
	int n;
	cin>>n;
	int x,y;
	queue<int>a,b;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x%2!=0) a.push(x);
		else if(x%2==0) b.push(x);
	}
	int f=0;
	while(!b.empty()||!a.empty()){
		if(!a.empty()){
		if(f==0){
			cout<<a.front();
			f=1;
		}else{
			cout<<" "<<a.front();
		}
		a.pop();	
		}
		if(!a.empty()){
			cout<<" "<<a.front();
			a.pop();
		}
		if(!b.empty()){
		if(f==0){
			cout<<b.front();
			f=1;
		}else{
			cout<<" "<<b.front();
		}
		b.pop();	
		}
	}
	return 0;
}


//求解迷宫从入口到出口的路径
#include<stdio.h>
typedef struct {
	int x,y;
}TT;
TT st[1000];
int s[11][11],t[11][11],k=0,n;
int tong(int x,int y);
int main(){
	int i,m,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&s[i][j]);
		}
	}
	if(tong(1,1)){
		for(i=k-1;i>=0;i--){
			printf("(%d,%d)",st[i].x,st[i].y);
		}
	}
	else printf("NO");
	return 0;
}
int tong(int x,int y){
	if(x==n-2&&y==n-2) {
		st[k].x=x;
		st[k].y=y;
		k++;
		return 1;
	}
	if(s[x][y]||t[x][y]) return 0;
	t[x][y]=1;
	if(tong(x,y+1)){
		st[k].x=x;
		st[k].y=y;
		k++;
		return 1;
	}
	else if(tong(x+1,y)){
		st[k].x=x;
		st[k].y=y;
		k++;
		return 1;
	}
	else if(tong(x,y-1)){
		st[k].x=x;
		st[k].y=y;
		k++;
		return 1;
	}
	else if(tong(x-1,y)){
		st[k].x=x;
		st[k].y=y;
		k++;
		return 1;
	}
	else{
		s[x][y]=1;
		return 0;
	}
}

//迷宫寻路
#include<bits/stdc++.h>
using namespace std;
struct items{
    int x,y;
};
int main()
{
    items pre,next;
    int g,h,Mark[100][100],flag=0,d=0,Len;
    int Move[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
    queue<items> Q;
    cin>>g>>h;
    while(g!=-1){
        for(int i=0; i<=g+1; i++){
            Mark[i][0]=1;
            Mark[i][h+1]=1;
        }
        for(int j=1; j<=h; j++){
            Mark[0][j]=1;
            Mark[g+1][j]=1;
        }
        for(int i=1; i<=g; i++){
            for(int j=1; j<=h; j++){
                cin>>Mark[i][j];
            }
        }
        pre.x=g;
        pre.y=h;
        Mark[g][h]=2;
        do{
            for(d=0; d<4; d++){
                next.x=pre.x+Move[d][0];
                next.y=pre.y+Move[d][1];
                if(Mark[next.x][next.y]==0){
                    Mark[next.x][next.y]=Mark[pre.x][pre.y]+1;
                    if(next.x==1&&next.y==1) break;
                    Q.push(next);
                }
            }
            if(next.x==1&&next.y==1){
                break;
            }
            if(Q.empty()==true){
                flag=1;
                break;
            }
            pre=Q.front();
            Q.pop();
        }
        while(true);
        while(!Q.empty()){
            Q.pop();
        }
        Len=Mark[1][1]-1;
        if(flag==1) cout<<"NO FOUND";
        else{
            pre.x=1;
            pre.y=1;
            cout<<"1,1"<<endl;
            for(int j=Len-1; j>0; j--){
                for(d=0; d<4; d++){
                    next.x=pre.x+Move[d][0];
                    next.y=pre.y+Move[d][1];
                    if(Mark[next.x][next.y]==j+1){
                        cout<<next.x<<','<<next.y<<endl;
                        break;
                    }
                }
                pre=next;
            }
        }
        flag=0;
        cin>>g>>h;
        cout<<endl;
    }
    return 0;
}

//二分查找
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
	int n,m;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cin>>m;
	int low=0,hight=n-1,mid,k=0,p=0,f=0;
	while(low<=hight){
		k++;
		mid=(low+hight)/2;
		if(a[mid]==m){
		p=mid;
		f=1;
		break;	
		}
		else if(a[mid]<m) low=mid+1;
		else if(a[mid]>m) hight=mid-1;
		}
	if( f==0) cout<<"-1"<<endl<<k<<endl;
	else cout<<p<<endl<<k<<endl;
	return 0;
}


//顺序存储的二叉树的最近的公共祖先问题
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
	int n;
	cin>>n;
	int aa[n];
	for(int i=1;i<=n;i++)
	cin>>aa[i];
	int a,b;
	cin>>a>>b;
	if(aa[a]==0) printf("ERROR: T[%d] is NULL",a);
	else if(aa[b]==0) printf("ERROR: T[%d] is NULL",b);
	else{
	while(1){
		if(a>b) a/=2;
		if(b>a) b/=2;
		if(a==b){
			cout<<a<<" "<<aa[a];
			break;
		}
	}	
	}
	
	return 0;
}


//列出叶结点
#include<bits/stdc++.h>
using namespace std;
struct node {
    char left, right;
} nd[15];
vector <int> leaf[15];
void fun(int s, int cur) {
    if (nd[s].left == '-' && nd[s].right == '-') {
        leaf[cur].push_back(s);
        return ;
    }
    if (nd[s].left != '-') fun(nd[s].left - '0', cur + 1);
    if (nd[s].right != '-') fun(nd[s].right - '0', cur + 1);
}
int main() {
    int n, root[10], rt = 0;
    memset(root, 0, sizeof root);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> nd[i].left >> nd[i].right;
        root[nd[i].left - '0'] = root[nd[i].right - '0'] = 1;
    }
    for (int i = 0; i < n; i++)
        if (!root[i]) {
            rt = i;
            break;
        }
    fun(rt, 1);
    bool f = false;
    for (int i = 1; i <= 10; i++) {
        for (int j = 0; j < leaf[i].size(); j++) {
            if (f) cout << " ";
            else f = true;
            cout << leaf[i][j];
        }
    }
    cout << endl;
}


//修理牧场
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
	int n;
	cin>>n;
	int a;
	priority_queue<int,vector<int>,greater<int> >v;
	for(int i=0;i<n;i++){
		cin>>a;
		v.push(a);
	}
	int x,y,sum=0;
	while(v.size()!=1){
		x=v.top();
		v.pop();
		y=v.top();
		v.pop();
		sum+=(x+y);
		v.push(x+y);
	}
	cout<<sum<<endl;
	return 0;
}


//哈夫曼树
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
	int n;
	cin>>n;
	int a;
	priority_queue<int,vector<int>,greater<int> >v;
	for(int i=0;i<n;i++){
		cin>>a;
		v.push(a);
	}
	int x,y,sum=0;
	while(v.size()!=1){
		x=v.top();
		v.pop();
		y=v.top();
		v.pop();
		sum+=(x+y);
		v.push(x+y);
	}
	cout<<sum<<endl;
	return 0;
}


//树的遍历
#include<bits/stdc++.h>
using namespace std;
vector<int>le(100009,-1);
vector<int>in,post;
void f(int inb,int ine,int postb,int poste,int k){
	if(inb>ine||postb>poste) return;
	int len=0;
	int key=post[poste];
	le[k]=key;
	while(in[inb+len]!=key) len++;
	f(inb,inb+len-1,postb,postb+len-1,k*2+1);
	f(inb+len+1,ine,postb+len,poste-1,k*2+2);
}
int main()
{
	int n,num=0;
	cin>>n;
	in.resize(n);
	post.resize(n);
	for(int i=0;i<n;i++)
	cin>>post[i];
	for(int i=0;i<n;i++)
	cin>>in[i];
	f(0,n-1,0,n-1,0);
	for(int i=0;i<le.size();i++){
		if(le[i]!=-1&&num!=n-1){
		cout<<le[i]<<" ";
		num++;
	}
		else if(le[i]!=-1)
		cout<<le[i];
	}
	return 0;
}

//求二叉树的叶子结点个数
#include<bits/stdc++.h>
using namespace std;
int k;
typedef struct ss{
	char data;
	struct ss *left,*right;
}*tree;
tree jian(){
	tree t;
	char ch;
	cin>>ch;
	if(ch=='#') return NULL;
	else{
		t=(tree)malloc(sizeof(struct ss));
		t->data=ch;
		t->left=jian();
		t->right=jian();
		 //if(t->left=NULL&&t->right=NULL) k++;
	}
	return t;
}
void zhong(tree t){
	if(t!=NULL){
		zhong(t->left);
		cout<<t->data;
		zhong(t->right);
		if(t->left==NULL&&t->right==NULL) k++;
	}
}
int main()
{
	tree t;
	t=jian();
	zhong(t);
	cout<<endl<<k<<endl;
	return 0;
}

//推断学生所属学校的人数
#include<bits/stdc++.h>
using namespace std;
const int N = 1004;
int root[N], cnt[N];
int find(int x){
	if(x != root[x]) root[x] = find(root[x]);
	return root[x];
}
int main(){
	int n;
	cin>>n;
	string str, a, b;
	unordered_map<string , int> mp;
	for(int i = 1; i <= n; i++){
		root[i] = i;
		cnt[i] = 1;
	}
	for(int i = 1; i <= n; i++){
		cin>>str;
		mp[str] = i;
	} 
	int m;
	cin>>m;
	while(m--){
		cin>>a>>b;
		int x = mp[a];
		int y = mp[b];
		int u = find(x), v = find(y);
		if(u != v){
			root[u] = v;
			cnt[v] += cnt[u];
		}
	}
	int numS = 0, maxS = 0;
	for(int i = 1; i <= n; i++){
		if(root[i] == i){
			numS++;
			maxS = max(maxS, cnt[i]);
		}
	}
	cout<<numS<<" "<<maxS;
	return 0;
}



//部落
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int pre[N],vis[N],cut1,cut2;
int f(int x){
	if(x==pre[x]) return x;
	else return pre[x]=f(pre[x]);
}
void bin(int a,int b){
	int aa=f(a);
	int bb=f(b);
	if(aa!=bb)
	pre[aa]=bb;
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<N;i++)
	pre[i]=i;
	while(n--){
		int k,x,y;
		cin>>k>>x;
		vis[x]=1;
		for(int i=1;i<k;i++){
			cin>>y;
			vis[y]=1;
			bin(x,y);
		}
	}
	for(int i=0;i<N;i++){
		if(vis[i]==1)
		cut1++;
	}
	for(int i=1;i<=cut1;i++){
		if(pre[i]==i)
		cut2++;
	}
	cout<<cut1<<" "<<cut2<<endl;
	int nn;
	cin>>nn;
	int aa,bb;
	while(nn--){
		cin>>aa>>bb;
		if(f(aa)==f(bb)) cout<<"Y\n";
		else cout<<"N\n";
	}
	return 0;
 } 



//树种统计
#include<bits/stdc++.h>
using namespace std;
int main()
{
	map<string,int>mh;
	map<string,int>::iterator h;
	int n;
	string s;
	cin>>n;
	getchar();
	for(int i=0;i<n;i++){
		getline(cin,s);
		mh[s]++;
	}
	double sum;
	for(h=mh.begin();h!=mh.end();h++){
		if(h->second!=0){
			cout<<h->first<<" ";
			sum=h->second*100.0/n;
			printf("%.4lf%%\n",sum);
		}
	}
	return 0;
 } 

//二叉树的遍历
#include<bits/stdc++.h>
using namespace std;
struct ss{
	int l,r;
}a[10001];
void xian(ss a[],int root){
	if(root!=0){
	cout<<root<<" ";
	 xian(a,a[root].l);
	 xian(a,a[root].r);
}
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i].l>>a[i].r;
	xian(a,1);
	return 0;
}


//列出所有祖先结点
#include<bits/stdc++.h>
using namespace std;
typedef struct {
	int left;
	int right;
} node;
int main() {
	int N;
	cin>>N;
	node a[N];           
	stack<int> result;
	for(int i=0; i<N; i++) {
		char c1,c2;
		getchar();     
		cin>>c1;
		getchar();     
		cin>>c2;
		if((c1>='0')&&(c1<='9')) {
			int l;
			l=c1-'0';
			a[i].left=l;
		} else {
			a[i].left=100;
		}
		if((c2>='0')&&(c2<='9')) {
			int r;
			r=c2-'0';
			a[i].right=r;
		} else {
			a[i].right=100;
		}
	}
	int k;
	cin>>k;
	int flag=1;
	while(flag==1) {
		int p;
		for(p=0; p<N; p++) {
			if((a[p].left==k)||(a[p].right==k)) {
				result.push(p);      
				k=p;                 
				break;
			}
		}
		if(p==N) {          
			flag=0;
		}
	}
	if(N<=1) {              
		cout<<"";
	} else {
		cout<<result.top();    
		result.pop();           
		while(result.empty()!=true) {
			cout<<" "<<result.top();
			result.pop();
		}
	}
	return 0;
}


//根据后序和中序遍历输出先序遍历
#include<bits/stdc++.h>
using namespace std;
vector<int>post,in,le,v;
void f(int inb,int ine,int postb,int poste){
	if(inb>ine||postb>poste) return;
	int len=0;
	int key=post[poste];
	le.push_back(key);
	v.push_back(key);
	while(in[inb+len]!=key) len++;
	f(inb,inb+len-1,postb,postb+len-1);
	f(inb+len+1,ine,postb+len,poste-1);
}
int main()
{
	int n;
	cin>>n;
	post.resize(n);
	in.resize(n);
	le.resize(n);
	for(int i=0;i<n;i++)
	cin>>post[i];
	for(int i=0;i<n;i++)
	cin>>in[i];
	f(0,n-1,0,n-1);
	cout<<"Preorder: ";
	for(int i=0;i<v.size();i++){
		cout<<v[i];
		if(i!=v.size()-1) cout<<" ";
	}
	return 0;
}

//邻接矩阵表示法创建无向图
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<int>v[N];
int main()
{
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	while(m--){
		getchar();
		char a=getchar();
		a=a-'A';
		char b=getchar();
		b=b-'A';
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i=0;i<n;i++){
		cout<<v[i].size();
		if(i!=n-1) cout<<" ";
	}
	return 0;
}


//旅游规划
#include<bits/stdc++.h>
using namespace std;
int N,M,S,D;
const int maxn=505;
const int INF=1e9;
int G[maxn][maxn],C[maxn][maxn],vis[maxn]={0},d[maxn],costs[maxn];
void Dijkstra(int s){
	fill(d,d+maxn,INF);
	fill(costs,costs+maxn,INF);
	d[s]=0;
	costs[s]=0;
	for(int i=0;i<N;i++){
		int Min = INF,u = -1;
		for(int j=0;j<N;j++){
			if(vis[j]==0 && d[j] < Min){
			u=j;
			Min=d[j];
			}
		}
	if(u ==  -1) return;
	vis[u]=1;
	for(int v=0;v<N	;v++){ 
		if(vis[v]==0 && G[u][v]!=INF ){
			if( d[u] +G[u][v] < d[v]){
				d[v]= G[u][v] + d[u];
				costs[v]=costs[u]+C[u][v];
				}else if(d[u] +G[u][v] == d[v] && costs[u] +C[u][v] < costs[v]){
					costs[v]=costs[u]+C[u][v];
			}
				
		}
	}
  }
}
int main(){
	int u,v,length,cost;
	cin>>N>>M>>S>>D;
	fill(G[0],G[0]+maxn*maxn,INF);
	for(int i=0;i<M;i++){
		cin>>u>>v>>length>>cost;
		G[u][v]=length;
		G[v][u]=length;
		C[u][v]=cost;
		C[v][u]=cost;
	}
	Dijkstra(S);
	cout<<d[D]<<" "<<costs[D]<<endl;
	return 0;
}



//城市间紧急救援 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define Inf 0x3f3f3f3f
const int maxn=1005;
int g[maxn][maxn];
int cnt[maxn],vis[maxn],cf[maxn],ccf[maxn],pre[maxn];
//最短路径条数,各城市是否经过,各城市救援队数量,到达该城市时所召集的救援队数量,到达该城市前经过的城市编号
int n,m,s,d;
//初始化 
void init()
{
  	cin>>n>>m>>s>>d;
	for(int i=0;i<n;i++)
	{
		cin>>cf[i];
		ccf[i]=cf[i];
		cnt[i]=1;
	}
	for(int i=0;i<n;i++)
	    for(int j=0;j<n;j++)
			if(i!=j)
	    	     g[i][j]=g[j][i]=Inf;
	int a,b,c;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b>>c;
		g[a][b]=g[b][a]=c;
	}   
}
void Dijkstra()
{
  	cnt[s]=1;
  	vis[s]=1;
    for(int k=0;k<n;k++)
  	{
  	  	int minn=Inf,u=-1;
  	  	for(int i=0;i<n;i++)
  	  	{
  	  	 	if(!vis[i]&&g[s][i]<minn)
  	  	 	{
  	  	 	    minn=g[s][i];
				u=i;
			}
		}
	    if(u==-1) break;
	    else  vis[u]=1;
	    for(int j=0;j<n;j++)
	    {
	   	    if(!vis[j]&&g[s][j]>g[s][u]+g[u][j])
	   	    {
	   	  	    g[s][j]=g[s][u]+g[u][j]; 
	   	  	    cnt[j]=cnt[u];
	   	  	    pre[j]=u;
	   	  	    ccf[j]=ccf[u]+cf[j];
		    }
		    else if(!vis[j]&&g[s][j]==g[s][u]+g[u][j])
		    {
		    	cnt[j]=cnt[u]+cnt[j];
		    	if(ccf[j]<ccf[u]+cf[j]) 
		    	{
		    		pre[j]=u;
					ccf[j]=ccf[u]+cf[j];
				}
			}
	   } 
    } 
}
int main()
{
  	init();
	Dijkstra();
	cout<<cnt[d]<<" "<<ccf[d]+cf[s]<<endl;
	int k=0,t=d;
	int road[maxn];
	while(pre[t]!=0)
	{
		road[k++]=pre[t];
		t=pre[t];
	}
	cout<<s<<" ";
	for(int i=k-1;i>=0;i--)
		cout<<road[i]<<" ";
	cout<<d<<endl;
  	return 0;
}


//公路村村通
#include<bits/stdc++.h>
using namespace std;
int n,m,pre[10001],k,sum;
struct ss{
	int a,b,c;
}p[10001];
bool cmp(ss a,ss b){
	return a.c<b.c;
}
int Find(int x){
	if(x==pre[x]) return x;
	else return pre[x]=Find(pre[x]);
}
void bin(int a,int b){
	int aa=Find(a),bb=Find(b);
	if(aa!=bb) pre[aa]=bb;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<10001;i++)
	pre[i]=i;
	for(int i=0;i<m;i++)
	cin>>p[i].a>>p[i].b>>p[i].c;
	sort(p,p+m,cmp);
	for(int i=0;i<m;i++){
		if(Find(p[i].a)!=Find(p[i].b)){
			k++;
			sum+=p[i].c;
			bin(p[i].a,p[i].b);
		}
	}
	if(k!=n-1) sum=-1;
	cout<<sum<<endl;
	return 0;
}

//电话聊天狂人 
#include<bits/stdc++.h>
using namespace std;
int main()
{
	map<string,int>mh;
	map<string,int>::iterator h;
	int n;
	cin>>n;
	string s,x;
	for(int i=0;i<n*2;i++){
		cin>>s;
		mh[s]++;
	}
	int max=0,sum=1;
	for(h=mh.begin();h!=mh.end();h++){
		if(h->second>max){
			max=h->second;
			x=h->first;
			sum=1;
		}
		else if(h->second==max)
		sum++;
	}
	if(sum==1) cout<<x<<" "<<max<<endl;
	else cout<<x<<" "<<max<<" "<<sum<<endl;
	return 0;
}


//航空公司VIP客户查询
#include<stdio.h>
#include<string.h>
#define N 500010
typedef long long ll;
struct count{
	ll num;
	char data[20];
}dt[N];
ll p,nt[N],idx=0;
ll is(ll x){
	for(ll i=2;i*i<=x;i++){
		if(x%i==0)return 0;
	}
	return 1;
}
ll key(char x[]){
	ll t=0,i;
	for(ll i=7;i<13;i++){
		t=t*10+(x[i]-'0');
	}
	return t%p;
}
ll find(char x[]){
	for(ll i=key(x);i!=-1;i=nt[i]){
		if(strcmp(dt[i].data,x)==0){
			return i;
		}
	}
	return -1;
}
void insert(char x[],ll num){
	ll f=find(x);
	if(f==-1){
		ll id=key(x);
		strcpy(dt[idx].data,x),dt[idx].num+=num;
		nt[idx]=nt[id],nt[id]=idx++;
	}
	else{
		dt[f].num+=num;
	}
}
int main(){
	ll num,n,k,i,t;
	char x[20];
	for(i=N-1;;i--){
		if(is(i)){
			p=i;
			break;
		}
	}
	for(i=0;i<N;i++){
		nt[i]=-1;
		dt[i].num=0;
	}
	scanf("%lld %lld",&n,&k);
	for(i=0;i<n;i++){
		getchar();
		scanf("%s %lld",&x,&num);
		if(num<k)num=k;
		insert(x,num);
	}
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		getchar();
		scanf("%s",&x);
		t=find(x);
		if(t==-1)puts("No Info");
		else printf("%lld\n",dt[t].num);
	}
	return 0;
}


//QQ帐户的申请与登陆
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s,w;
	map<string,string>mp;
	char c;
	while(n--){
		cin>>c>>s>>w;
		if(c=='L'){
			if(mp.find(s)==mp.end())
			cout<<"ERROR: Not Exist\n";
			else{
				if(mp[s]==w) cout<<"Login: OK\n";
				else cout<<"ERROR: Wrong PW\n";
			}
		}
		else{
			if(mp.find(s)==mp.end()){
				cout<<"New: OK\n";
				mp[s]=w;
			}
			else cout<<"ERROR: Exist\n";
		}
	}
	return 0;
 } 


//A-B 
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,f;
	getline(cin,s);
	getline(cin,f);
	int a[1000]={0};
	for(int i=0;i<f.size();i++){
		a[f[i]]=1;
	}
	for(int i=0;i<s.size();i++){
		if(a[s[i]]==0)
		cout<<s[i];
	}
	return 0;
}


//单链表逆转
#include <stdio.h>
#include <stdlib.h>

typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node {
    ElementType Data;
    PtrToNode   Next;
};
typedef PtrToNode List;

List Read(); /* 细节在此不表 */
void Print( List L ); /* 细节在此不表 */

List Reverse( List L );

int main()
{
    List L1, L2;
    L1 = Read();
    L2 = Reverse(L1);
    Print(L1);
    Print(L2);
    return 0;
}
List Reverse( List L ){
	List head,tail,mid;
	tail=NULL;
	mid=L;
	while(mid!=NULL){
		head=mid->Next;
        mid->Next=tail;
		tail=mid;
		mid=head;
	}
	return tail;
}


//顺序表操作集
#include <stdio.h>
#include <stdlib.h>

#define MAXSIZE 5
#define ERROR -1
typedef enum {false, true} bool;
typedef int ElementType;
typedef int Position;
typedef struct LNode *List;
struct LNode {
    ElementType Data[MAXSIZE];
    Position Last; /* 保存线性表中最后一个元素的位置 */
};

List MakeEmpty(); 
Position Find( List L, ElementType X );
bool Insert( List L, ElementType X, Position P );
bool Delete( List L, Position P );

int main()
{
    List L;
    ElementType X;
    Position P;
    int N;

    L = MakeEmpty();
    scanf("%d", &N);
    while ( N-- ) {
        scanf("%d", &X);
        if ( Insert(L, X, 0)==false )
            printf(" Insertion Error: %d is not in.\n", X);
    }
    scanf("%d", &N);
    while ( N-- ) {
        scanf("%d", &X);
        P = Find(L, X);
        if ( P == ERROR )
            printf("Finding Error: %d is not in.\n", X);
        else
            printf("%d is at position %d.\n", X, P);
    }
    scanf("%d", &N);
    while ( N-- ) {
        scanf("%d", &P);
        if ( Delete(L, P)==false )
            printf(" Deletion Error.\n");
        if ( Insert(L, 0, P)==false )
            printf(" Insertion Error: 0 is not in.\n");
    }
    return 0;
}
List MakeEmpty(){
    List p;
    p = (List)malloc(sizeof(struct LNode));
    p->Last = -1;
    return p;
}
Position Find( List L, ElementType X ){
    int i;
    for(i = 0; i <= L->Last; i++){
        if(X==L->Data[i]){
            return i;
        }
    }
    return ERROR;
}
bool Insert( List L, ElementType X, Position P ){
    if(L->Last==MAXSIZE-1){
        printf("FULL");
        return false;
    }
    if(P<0||P>L->Last+1){
	        printf("ILLEGAL POSITION");
        return false;
    }
    int i;
    for(i = L->Last+1; i > P; i--){
        L->Data[i] = L->Data[i-1];
    }
    L->Data[i] = X;
    L->Last++;
    return true;
}
bool Delete( List L, Position P ){
    int i;
        if(P<0||P>L->Last){
		        printf("POSITION %d EMPTY",P);
        return false;
    }
    for(i = P; i < L->Last; i++){
        L->Data[i] = L->Data[i+1];
    }
    L->Last--;
    return true;
}


//递增的整数序列链表的插入
#include <stdio.h>
#include <stdlib.h>

typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node {
    ElementType Data;
    PtrToNode   Next;
};
typedef PtrToNode List;

List Read(); /* 细节在此不表 */
void Print( List L ); /* 细节在此不表 */

List Insert( List L, ElementType X );

int main()
{
    List L;
    ElementType X;
    L = Read();
    scanf("%d", &X);
    L = Insert(L, X);
    Print(L);
    return 0;
}
List Insert( List L, ElementType X ){
	PtrToNode p,q;
	for(p=L;p->Next!=NULL;p=p->Next){
		if(p->Next->Data>=X)
		break;
	}
	q=(PtrToNode)malloc(sizeof(struct Node));
	q->Data=X;
	q->Next=p->Next;
	p->Next=q;
	return L;
}


//顺序表的查找操作
typedef struct{
    ElemType *elem;
    int length;
 }SqList;
    ```

### 裁判测试程序样例:
```c++
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 5
typedef int ElemType;
typedef struct{
    ElemType *elem;
    int length;
 }SqList;
void InitList(SqList &L);/*细节在此不表*/
int LocateElem(SqList L,ElemType e);

int main()
{
    SqList L;
    InitList(L);
    ElemType e;
    int p;
    scanf("%d",&e);
    p=LocateElem(L,e);
    printf("The position of %d in SequenceList L is %d.",e,p);
    return 0;
}
int LocateElem(SqList L,ElemType e)
{
	for(int i = 0 ;i <L.length; i++)
	{
		if(L.elem[i]==e)
			return i+1;
	}
	return 0;
}


//求链表的倒数第m个元素
#include <stdio.h>
#include <stdlib.h>

#define ERROR -1

typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node {
    ElementType Data;
    PtrToNode   Next;
};
typedef PtrToNode List;

List Read(); /* 细节在此不表 */
void Print( List L ); /* 细节在此不表 */

ElementType Find( List L, int m );

int main()
{
    List L;
    int m;
    L = Read();
    scanf("%d", &m);
    printf("%d\n", Find(L,m));
    Print(L);
    return 0;
}
ElementType Find( List L, int m ){
	int len,i;
	PtrToNode p;
for(p=L->Next;p!=NULL;p=p->Next)
	len++;
	if(len<m)
	return ERROR;
	else {
		i=0;
		for(p=L->Next;p!=NULL;p=p->Next){
			i++;
			if(i==len-m+1)
			return p->Data;
		}
	}
}


//求二叉树高度
#include <stdio.h>
#include <stdlib.h>

typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;
struct TNode{
    ElementType Data;
    BinTree Left;
    BinTree Right;
};

BinTree CreatBinTree(); /* 实现细节忽略 */
int GetHeight( BinTree BT );

int main()
{
    BinTree BT = CreatBinTree();
    printf("%d\n", GetHeight(BT));
    return 0;
}
int GetHeight( BinTree BT ){
	int h,l,r;
	if(BT){
		l=GetHeight(BT->Left);
		r=GetHeight(BT->Right);
		if(l>r) h=l;
		else h=r;
		return h+1;
	}
	else return 0;
}


///二叉树的遍历
#include <stdio.h>
#include <stdlib.h>

typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;
struct TNode{
    ElementType Data;
    BinTree Left;
    BinTree Right;
};

BinTree CreatBinTree(); /* 实现细节忽略 */
void InorderTraversal( BinTree BT );
void PreorderTraversal( BinTree BT );
void PostorderTraversal( BinTree BT );
void LevelorderTraversal( BinTree BT );

int main()
{
    BinTree BT = CreatBinTree();
    printf("Inorder:");    InorderTraversal(BT);    printf("\n");
    printf("Preorder:");   PreorderTraversal(BT);   printf("\n");
    printf("Postorder:");  PostorderTraversal(BT);  printf("\n");
    printf("Levelorder:"); LevelorderTraversal(BT); printf("\n");
    return 0;
}
void InorderTraversal( BinTree BT ){
    if(BT){
        if(BT->Left)
		InorderTraversal(BT->Left);
        printf(" %c",BT->Data);
        if(BT->Right)
		InorderTraversal(BT->Right);
    }
}
void PreorderTraversal( BinTree BT ){
    if(BT){
        printf(" %c",BT->Data);
        if(BT->Left)
		PreorderTraversal(BT->Left);
        if(BT->Right)
		PreorderTraversal(BT->Right);
    }
}
void PostorderTraversal( BinTree BT ){
    if(BT){
        if(BT->Left)
		PostorderTraversal(BT->Left);
        if(BT->Right)
		PostorderTraversal(BT->Right);
        printf(" %c",BT->Data);
    }
}
void LevelorderTraversal( BinTree BT ){
    BinTree que[101],t;
    int head=0,rear=0;
    if(BT){
        que[rear++]=BT;
        while(head!=rear){
            t=que[head++];
            printf(" %c",t->Data);
            if(t->Left)
			que[rear++]=t->Left;
            if(t->Right)
			que[rear++]=t->Right;
        }
    }
}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值