昨天的面试题,很郁闷,工作很难找,路漫漫,该怎样求索

Hello_friend_hao 2008-10-26 10:32:09
1
#define myprintf(x) printf("the parament "#x" is %d\n",_____)  //填上这个空使下面的输出成立
int main(void)
{
int a = 2;
int b = 9;
int c = 10;
myprintf(1);
myprintf(2);
myprintf(3);
return 0;
}
the parament 1 is 2
the parament 1 is 9
the parament 1 is 10

我想这个考的不是数字之间的逻辑关系吧

2 编程题
问题:寻找攻击的IP
问题描叙如下:
现有个web服务器,希望从访问服务器的IP访问信息中找出攻击的IP,也就是短时间内频繁访问的IP。
假设访问每条信息包含两部分内容:IP地址,访问时间。其中IP地址范围从0.0.0.0到255.255.255.255,如:124.144.174.44
访问时间范围从00:00:00到23:59:59

令在单位时间X秒之内访问量超过Y次的IP为攻击IP。请写一个程序根据IP访问信息找出攻击IP

输入:
1、IP信息行数N:unsigned int,N < 1000000000
2、接下来N行,每行代表一条IP访问信息,含有IP地址,访问时间。通过空格分隔。(假设N行信息已经按照时间先后排序)
3、参数X,Y:代表攻击阈值,X秒之内访问超过Y次的IP
示例文件:

[code=BatchFile]4
144.74.44.94 11:11:10
144.74.44.94 11:11:11
144.74.44.94 11:11:11
144.74.44.94 11:11:11
[/code]
输出:
有攻击特征的IP(注意:相同的IP只输出一次)

3 以下的程序执行到哪行崩溃
int main(void)
{
struct a
{
char p;
char *q;
}st;
int *p = (int *)&st.p;
p[0] //题目未完,让我先从崩溃状态回复过来先
p[1]
p[2]
p[3]
p[5]
p = st.q;
p[5]
p[4]
p[3]
p[2]
p[1]
}

这个题目有些记不清了,当时我就想,这个程序还没有崩溃,我先崩溃了
...全文
181 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
chattelg 2008-10-26
  • 打赏
  • 举报
回复
#define myprintf(x) printf("the parament "#x" is %d\n", *(&a-x+1))
piaomiaoju 2008-10-26
  • 打赏
  • 举报
回复

#define myprintf(x) printf("the parament "#x" is %d\n",*((int *)(&a)-3*(x-1)))
//我的机器上这样可以调试出来,但是奇怪的是,应该是压双字,3应该是2才对,不解??
machaoqun6666 2008-10-26
  • 打赏
  • 举报
回复
第一题这样行吧 x==1?2:(x==2?9:10)
machaoqun6666 2008-10-26
  • 打赏
  • 举报
回复
第3题 http://topic.csdn.net/u/20081019/16/187dfb4c-3fed-4569-8abe-44fd45aab429.html
lzr4304061988012 2008-10-26
  • 打赏
  • 举报
回复
the parament 1 is 2
the parament 1 is 9
the parament 1 is 10
这个输出没问题吗?
Hello_friend_hao 2008-10-26
  • 打赏
  • 举报
回复
呆会加分
K行天下 2008-10-26
  • 打赏
  • 举报
回复
第一个 p[2]
就要崩溃改写了main函数
Hello_friend_hao 2008-10-26
  • 打赏
  • 举报
回复
哎 回来了,又是一个没有收获的的一天
icansaymyabc 2008-10-26
  • 打赏
  • 举报
回复
第一题100%是楼主写错了,输出应该是
the parament 1 is 2
the parament 2 is 9
the parament 3 is 10


综合这3个题目,估计楼主去面试的这家公司是家安全软件开发公司,否则的话,其他应用不需要对c/c++编译标准搞得这么清楚。
artszhao 2008-10-26
  • 打赏
  • 举报
回复
第二题用hash table来初始化一定时间段之内的IP地址。
such as:在00:00:00-23:59:59之内的时间是X;
那么fopen(handle,"file.txt",'r');
读取信息,之后将IP地址换成unsigned int数。
然后,简历hashtable。
将每个IP的count记录下来。。
若count大于Y(阀值),即位所求的IP.

int a[N]; //here is the ip info for the timer span of X.
static int OutIP[N];
int IP[4];

typedef unsigned int Uint;
typedef struct IP {
int ip[4];
Uint value;
};

typedef ENUM HAVEORNOT {
HAVEKEY;
HAVENOTKEY;
NULL;
}
typedef struct Hashtable {
HAVEORNOT keyflag;
Uint value;
int count;
};

Uint TransfIP(int *ip)
{
return (ip[3]*256*256*256+ip[2]*256*256+ip[1]*256+ip[0]);
}

int* InvTransfIP(Uint ipv)
{
//the inverse of TransfIP to get the according IP[4];
}

void Hashinit(Hashtable *k)
{
//init the hashtable;
k.keyflag = NULL;
k.value = 0;
k.count = 0;
}

Uint hackedIP(Uint N, Uint x, Uint y)
{
Hashtable Hip;
Hashinit(&Hip);
//creat the hashtable for the ip;
int i, j, time;
while(x--)
{
//abstract the ip info to store into a[N];
fopen(handle, "file.txt", "r");
a = fread(handle, N, "r");
}
for(i=0; i<N; i++)
{
Hip[i].value = TransfIP(a[i]);
Hip[i].keyflag = HAVEKEY;
Hip[i].count += 1;
}

for(j=0; j<N; j++)
{
if(Hip[i].keyflat==HAVEKEY && Hip[i].count > Y)
OutIP[k++] = InvTransfIP(Hip[i].value);
}

return OutIP;
}

int
main()
{
//you can write the test case to verify.

}

hagangqiou 2008-10-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 machaoqun6666 的回复:]
第一题这样行吧  x==1?2:(x==2?9:10)
[/Quote]呵呵

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧