“臭味相投”——这是我们描述朋友时喜欢用的词汇。两个人是朋友通常意味着他们存在着许多共同的兴趣。然而作为一个宅男,你发现自己与他人相互了解的机会 并不太多。幸运的是,你意外得到了一份北大图书馆的图书借阅记录,于是你挑灯熬夜地编程,想从中发现潜在的朋友。
首先你对借阅记录进行了一番整理,把N个读者依次编号为1,2,…,N,把M本书依次编号为1,2,…,M。同时,按照“臭味相投”的原则,和你喜欢读同一本书的人,就是你的潜在朋友。你现在的任务是从这份借阅记录中计算出每个人有几个潜在朋友。
每个案例第一行两个整数N,M,2 <= N ,M<= 200。接下来有N行,第i(i = 1,2,…,N)行每一行有一个数,表示读者i-1最喜欢的图书的编号P(1<=P<=M)
每个案例包括N行,每行一个数,第i行的数表示读者i有几个潜在朋友。如果i和任何人都没有共同喜欢的书,则输出“BeiJu”(即悲剧,^ ^)
4 5 2 3 2 1
1 BeiJu 1 BeiJu
#include
#include
int main()
{
int book[210],n,m,num[210];
//book[i]数组表示图书i有几个人借阅
//num[i]数组表示读者i借阅了哪本书
while(scanf("%d%d",&n,&m) != EOF)
{
memset(book,0,sizeof(book));
for(int i=0;i=2)
{
printf("%d\n",book[num[i]]-1);
}
else printf("BeiJu\n");
}
}
return 0;
}
先输入一组数,然后输入其分组,按照分组统计出现次数并输出,参见样例。
输入第一行表示样例数m,对于每个样例,第一行为数的个数n,接下来两行分别有n个数,第一行有n个数,第二行的n个数分别对应上一行每个数的分组,n不超过100。
输出m行,格式参见样例,按从小到大排。
1 7 3 2 3 8 8 2 3 1 2 3 2 1 3 1
1={2=0,3=2,8=1} 2={2=1,3=0,8=1} 3={2=1,3=1,8=0}
Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1, 104]. The first one who bets on a unique number wins. For example, if there are 7 people betting on 5 31 5 88 67 88 17, then the second one who bets on 31 wins.
Each input file contains one test case. Each case contains a line which begins with a positive integer N (<=105) and then followed by N bets. The numbers are separated by a space.
For each test case, print the winning number in a line. If there is no winner, print "None" instead.
7 5 31 5 88 67 88 17 5 888 666 666 888 888
31 None
#include
#include
//在num[i]中第一个只出现过一次的数字即为unique number
int hash[100001];
int num[100001];
int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
memset(hash,0,sizeof(hash));
for(int i=0;i
Given two strings S1 and S2, S = S1 - S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1 - S2for any given strings. However, it might not be that simple to do it fast.
Each input file contains one test case. Each case consists of two lines which gives S1 and S2, respectively. The string lengths of both strings are no more than 104. It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.
For each test case, print S1 - S2 in one line.
They are students. aeiou
Thy r stdnts.
#include
#include
char s1[10010],s2[10010],s[10010];
int main()
{
int flag,count;
while(gets(s1) != NULL)
{
gets(s2);
int len1=strlen(s1);
int len2=strlen(s2);
count=0;
memset(s,0,sizeof(s));
for(int i=0;i