题目描述:
2月14情人节了,我决定造福大家。第2个赞和第14个赞的,我介绍你俩认识…………咱三吃饭…你俩请…”。现给出此贴下点赞的朋友名单,请你找出那两位要请客的倒霉蛋。
输入描述:
输入按照点赞的先后顺序给出不知道多少个点赞的人名,每个人名占一行,为不超过10个英文字母的非空单词,以回车结束。一个英文句点.标志输入的结束,这个符号不算在点赞名单里。
输出描述:
根据点赞情况在一行中输出结论:若存在第2个人A和第14个人B,则输出“A and B are inviting you to dinner…”;若只有A没有B,则输出“A is the only one for you…”;若连A都没有,则输出“Momo… No one is for you …”。
代码
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
class A
{
public:
int len;
int index;
char **s;
A()
{
len=100;
index=-1;
s=get(len);
}
char **get(int len)
{
char **t=(char**)malloc(sizeof(char*)*len);
for(int i=0;i<len;i++)
t[i]=(char*)malloc(sizeof(char)*15);
return t;
}
void add(char *temp)
{
if(index==len-1)
{
char **t=get(len+100);
for(int i=0;i<len;i++)
{
for(int j=0;j<15;j++)
t[i][j]=s[i][j];
}
s=t;
len+=100;
}
int c=strlen(temp);
index++;
for(int i=0;i<=c;i++)
s[index][i]=temp[i];
}
char* prin(int i)
{
return s[i-1];
}
int exist(int i)
{
if((i-1)<=index)
return 1;
else
return 0;
}
};
int main()
{
A a;
char t[15];
while(gets(t)&&t[0]!='.')
{
a.add(t);
}
if(a.exist(2)==0)
{
printf("Momo... No one is for you ...\n");
}
else if(a.exist(14)==0)
{
printf("%s is the only one for you...\n",a.prin(2));
}
else
printf("%s and %s are inviting you to dinner...\n",a.prin(2),a.prin(14));
}