Created
March 20, 2019 11:43
-
-
Save yanring/12e8769f59b233d7959d8e284a06859d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int daxie[26],xiaoxie[26]; | |
string str; | |
void scan(string str){ | |
int len = str.size(); | |
for(char c : str){ | |
if(c <= 'Z' and c>='A'){ | |
daxie[c-'A']++; | |
}else if(c<='z' and c>='a'){ | |
xiaoxie[c-'a']++; | |
} | |
} | |
} | |
int find_start_index(){ | |
int count = 0, start_index = -1, max_count=0; | |
for(int i = 25; i >= 0 ; i--){ | |
if(daxie[i]>0 && xiaoxie[i]>0){ | |
count++; | |
if(count >= max_count){ | |
max_count = count; | |
start_index = i; | |
} | |
}else{ | |
count=0; | |
} | |
} | |
return start_index; | |
} | |
void print_res(){ | |
int pair_count = 0, start_index=-1; | |
while(1){ | |
start_index = find_start_index(); | |
if(start_index == -1) | |
break; | |
else{ | |
while(daxie[start_index]>0 && xiaoxie[start_index]>0){ | |
cout<<(char)('A'+start_index)<<(char)('a'+start_index); | |
daxie[start_index] --; | |
xiaoxie[start_index] --; | |
start_index ++; | |
} | |
cout<<endl; | |
} | |
} | |
} | |
int main(int argc, char *argv[]) { | |
while(1){ | |
memset(daxie, 0, sizeof(daxie)); | |
memset(daxie, 0, sizeof(xiaoxie)); | |
cin>>str; | |
scan(str); | |
if(find_start_index()>-1) | |
print_res(); | |
else | |
cout<<"Not Found"<<endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment