标签:
A.前缀hash+逆元
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <stack> #include <string> #include <vector> #include <map> #include <algorithm> const int inf = 0x3f3f3f; const int MAXN = 1e7+10; using namespace std; int main() { int n; char ts[40]; map<string,int>hash; map<string,int>::iterator li; while(scanf("%d",&n)!=EOF){ hash.clear(); for(int i=0;i<n;i++){ scanf("%s",ts); int len = strlen(ts); sort(ts,ts+len); string tmp = (string)ts; li = hash.find(tmp); if(li==hash.end()){ cout<<0<<endl; hash[tmp]++; }else{ cout<<hash[tmp]<<endl; hash[tmp]++; } } } //cout << "Hello world!" << endl; return 0; }
D.sort+map
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <stack> #include <string> #include <vector> #include <map> #include <algorithm> const int inf = 0x3f3f3f; const int MAXN = 1e7+10; using namespace std; int main() { int n; char ts[40]; map<string,int>hash; map<string,int>::iterator li; while(scanf("%d",&n)!=EOF){ hash.clear(); for(int i=0;i<n;i++){ scanf("%s",ts); int len = strlen(ts); sort(ts,ts+len); string tmp = (string)ts; li = hash.find(tmp); if(li==hash.end()){ cout<<0<<endl; hash[tmp]++; }else{ cout<<hash[tmp]<<endl; hash[tmp]++; } } } //cout << "Hello world!" << endl; return 0; }
标签:
原文地址:http://www.cnblogs.com/EdsonLin/p/5493448.html