Back to the Training Home
Back to the Training Home
Lesson: 44
Problem: 2990
Title: Simple Task
Difficulty Level: 2.0
Date: MAR 03, 2009
Site: http://acm.tju.edu.cn/toj/showp2990.html
Very good one for beginners. Try to figure out the logic from my code to solve this problem.
#include<stdio.h>
#define maxn 20001
#define CON 10000
int F[maxn];
void Cal() {
int m, res = 0, n, need;
scanf("%d",&n);
for(int i = 0; i<n; i++) {
scanf("%d",&m);
need = 0 - m + CON;
res += F[need];
}
printf("%d\n",res);
for(n = 0; n<maxn; n++) F[n] = 0;
}
int main() {
int kase, n, m;
freopen("h.txt","r",stdin);
scanf("%d",&kase);
while(kase--) {
scanf("%d",&n);
while(n--) {
scanf("%d",&m);
m += CON;
F[m] ++;
}
Cal();
}
return 0;
}
|