# 594. Cross Connection

[Title Description:

Now there is a string, the number of times each letter appears are even. Next we put the first occurrence of the letter a and the second occurrence of a connecting line, and four for the third occurrence of the letter a appears even a line, the fifth and sixth appearance of the emergence of a letter even a line ... other 25 letters have done the same thing.

Now we want to know how many pair of wires crossed. The endpoint is defined as a cross-connection within a further connection, the other end on the outside.

[Input Description:

A string line. Guaranteed by the lower case letter string, the number of occurrences of each letter and even-numbered.

[Output] Description:

An integer that represents the answer.

[Sample input]:

abaazooabz

[] Sample output:

3

[Sample] Description:

/

[Time limit, and the range of data Description:

Time: 2s space: 256M

For 30% of the data string length does not exceed 50.

To 100% of the data string length does not exceed 100,000.

 

 

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
char s[100610];
int kdl[36],ans,las[36];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++){
		int q=s[i]-'a'+1;
		kdl[q]++;
		kdl[q]%=2;
		if(kdl[q]==0){
			for(int j=1;j<=26;j++){
				if(las[j]>las[q]&&kdl[j]){
					ans++;
				}
			}
		}
		las[q]=i;
	}
	printf("%d\n",ans);
	return 0;
}

  

Guess you like

Origin www.cnblogs.com/xiongchongwen/p/11601077.html