codechef TIDRICE - "popular rice recipe" solution: http://ideone.com/5XLror
#include <iostream>#include <cstdio>
#include <cstring>
using namespace std;
int main() {
int t, n, v[105], cnt;
char id[105][25], c;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
cnt=0;
for(int i=0; i<n; i++) {
scanf("%s %c", id[i], &c);
(c=='+') ? v[i]=1 : v[i]=-1;
}
for(int i=n-1; i>0; i--) {
if(v[i]==0) continue;
for(int j=i-1; j>=0; j--) {
if(strcmp(id[i], id[j])==0) v[j]=0;
}
}
for(int i=0; i<n; i++) cnt += v[i];
printf("%d\n", cnt);
}
return 0;
}
No comments:
Post a Comment