/* map關聯容器:
介紹:
map是一個關聯容器,它可以提供一對一(其中第一個可以稱為關鍵字,每個關鍵字隻能在map中隻出現一次,第二個可能稱為該關鍵字的值)
的資料處理能力,意思就是可以實作類似k[cds111] = 2的功能,除此之外,map還會對資料自動排序
調用頭檔案:
#include<map>
using namespace std;
詳細用法(部分):
例如:
map<string, int> p; ------ 定義一個字元串與整型關聯容器,其中每個字元串都對應着一個整數,即每個字元串都為獨特的key
對應上面的容器有:
p["student"] = 2; ------ 插入(覆寫)key,且字元串(key)"student"值為2(預設為0)
p[key] ------- 表示key對應的值
p.count("student") ------ 查找p裡是否有key:"student",有的話傳回1,否則傳回0
p.erase("student") ------ 删除key:"student",成功傳回1,否則傳回0
p.empty() ------ 判斷容器是否為空,是的話傳回1,不是傳回0
p.clear() ------ 清空容器
p.size() ------ 傳回容器中key個數
*/
/* http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=690&pid=1004 */
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
map<string, int> p;
int main(void)
{
int T, len;
char str[40];
string str2;
scanf("%d", &T);
while(T--)
{
scanf("%s", str);
len = strlen(str);
sort(str, str+len); /*對字元串進行排序*/
str2.assign(str); /*将C類的字元串轉為C++的String以便作為key進入map*/
p[str2]++; /*字元串(key)str對應的值+1*/
printf("%d\n", p[str2]-1);
}
return 0;
}