題 意: 給一個字串,輸出這個字串所有的排序,輸出的排序要以 "字母順序" 輸出,(字母順序: AaBbCc......Zz)。
解法: 擅用STL。
TAG: STL
注意:
程式碼:
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
/** | |
* Tittle: 195 - Anagram | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/03/20 | |
*/ | |
// include files | |
#include <iostream> | |
#include <cstdio> | |
#include <cstring> | |
#include <cctype> | |
#include <algorithm> | |
#include <string> | |
using namespace std; | |
// definitions | |
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i ) | |
#define clr(x,v) memset( x, v, sizeof(x) ) | |
// declarations | |
int n; | |
string s; | |
// functions | |
bool cmp( char A, char B ) | |
{ | |
bool isua = isupper( A ); | |
bool isub = isupper( B ); | |
if( isua ) A = A-'A'+'a'; | |
if( isub ) B = B-'A'+'a'; | |
if( (isua^isub) && A==B ) return isua; | |
return A<B; | |
} | |
// main function | |
int main( void ) | |
{ | |
// input | |
scanf( "%d", &n ); | |
while( n-- ) { | |
cin >> s; | |
// solve & output | |
sort( s.begin(), s.end(), cmp ); | |
do { | |
cout << s << endl; | |
} while( next_permutation( s.begin(), s.end(), cmp ) ); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽