Codeforces Round #371 (Div. 2) C
map或者字典数的应用 简单题
题意:
思路:
AC代码:
1 #include<iostream> 2 #include<cstring> 3 #include<cmath> 4 #include<map> 5 #include<algorithm> 6 #include<cstdio> 7 #define max(a,b) a>b?a:b 8 #define F(i,a,b) for(int i=a;i<=b;i++) 9 #define mes(a,b) memset(a,b,sizeof(a)) 10 #define INF 0x3f3f3f3f 11 #define LL long long 12 using namespace std; 13 const int N=10010,MAX=1000100; 14 15 void fun(char *s) 16 { 17 int l = 0; 18 for(int i=0; i<strlen(s); i++) 19 { 20 if(s[i] == '0') 21 l++; 22 else 23 break; 24 } 25 for(int i=l-1; i<=strlen(s); i++) 26 { 27 s[i-l+1] = s[i+1]; 28 } 29 if(*s == '\0') 30 { 31 *s = '0'; 32 s[1] = '\0'; 33 } 34 } 35 36 int main() 37 { 38 int n; 39 char c,s[20]; 40 map<string,int>M; 41 scanf("%d",&n); 42 while(n--) 43 { 44 cin>>c>>s; 45 int l = strlen(s); 46 for(int i=0; i<l; i++) 47 { 48 if(s[i]&1) 49 s[i] = '1'; 50 else 51 s[i] = '0'; 52 } 53 //puts(s); 54 fun(s); 55 //puts(s); 56 if(c == '+') 57 M[s]++; 58 if(c == '-') 59 M[s]--; 60 if(c == '?') 61 cout<<M[s]<<endl; 62 } 63 return 0; 64 }