寻找黑客(怎么找黑客的联系方式)

题目链接程序#include<stdio.h>#include<stdlib.h>#include<string.h>#defineMAXREQS15000#defineSUMLEN1500typedefstructRequests{charsender[10];//sendername,allreciv…

大家好,又见面了,我是你们的朋友全栈君。

题目链接

程序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXREQS 15000
#define SUMLEN 1500

typedef struct Requests
{
    char sender[10]; //sender name, all recivers are the same
    int length;  //the length of each request
}Reqs;
typedef struct Senders
{
    char name[10]; //sender name
    int Newlength;  //the total length of each sender
}Send;

//check if str[] is in the send[], if yes return its procession, if no return -1
int IsRepeat(char str[], Send send[])
{
    int i = 0;
    int index = -1;
    for(i=0; i<MAXREQS; i++)
    {
        if (strcmp(str, send[i].name) == 0)
        {
            index = i;
            break;
        }
    }
    return index;
}

int main(int argc, char *argv[])
{
    FILE *fp1,*fp2;
    Reqs reqs[MAXREQS] = {
   
   {},{},{},{},{},{},{},{}}; //max num we can process is MAXREQS
    Send send[MAXREQS] = {
   
   {},{},{},{},{},{},{},{}};
    int i=0,j=0,index=0,HackNum=0; 

    if(argc == 1){
        printf("error, have not entered file name\n");
        exit(0);
    }
    else if(argc > 1)
    {
        if((fp1=fopen(argv[1],"r")) == NULL){
            printf("error, cannot open %s\n",argv[1]);
            exit(0);
        }
        if(argc == 2)
            fp2 = stdout;
        else
            fp2=fopen(argv[2],"w");
    }

    i=0;j=0;
    while(fscanf(fp1,"%s%*s%d",reqs[i].sender,&reqs[i].length) != EOF)
    {
        index = IsRepeat(reqs[i].sender, send);
        if (index == -1)
        {
            strcpy(send[j].name,reqs[i].sender);
            send[j].Newlength = reqs[i].length;         
            j++;
        }
        else
        {
            //update the repeat value
            send[index].Newlength = send[index].Newlength + reqs[i].length;
        }
        i++;
    }
    
    //find the hackers who's length is more than SUMLEN
    for(i=0; i<j; i++)
    {
        if(send[i].Newlength >= SUMLEN)
        {
            HackNum++;
        }
    }
    fprintf(fp2,"%d\n",HackNum);
    for(i=0; i<j; i++)
    {
        if(send[i].Newlength >= SUMLEN)
        {
            fprintf(fp2,"%s\n",send[i].name);
        }
    }
    fclose(fp1);
    fclose(fp2);
    return 0;
}

运行结果

1283331-20190606132713770-1491991423.png

1283331-20190606132858795-255641771.png

1283331-20190606132930136-251688783.png

转载于:https://www.cnblogs.com/fjlinww/p/10909212.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/125536.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 学习Python必备的8本书[通俗易懂]

    在过去一年里,Python的热度一路飙升,国内越来越多的人选择学习Python,如今已然成为大量开发者推荐的入门编程语言和第二编程语言,而且Python还是人工智能的主要编程语言,因此,其重要性和流行度也就不言而喻了想要学好Python语言,需要了解Python是什么,都能够做什么,知道算法,变量,解释器,还有Python的基本数据类型等。所以,本文将推荐几本学习Python编程必看的几本书籍…

    2022年4月14日
    59
  • ubuntu20更换国内源_ubuntu更换国内源

    ubuntu20更换国内源_ubuntu更换国内源[Fedora-ftp.sjtu.edu.cn]name=Fedora12-i386baseurl=http://ftp.sjtu.edu.cn/fedora/linux/releases/12/Fedora/i386/os/enabled=1gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora[Eve

    2022年9月20日
    3
  • shell脚本之awk数组

    shell脚本之awk数组一.数组格式数组是一个包含一系列元素的表.格式如下:abc[1]=”xiaohong”abc[2]=”xiaolan”解释:abc:为数组名称[1]、[2]:为数组元素下标,可以理解为数组的第1个元素、数组的第2个元素xiaohong、xiaolan:元素值例子1:定义数组,并且打印数组元素[root@tab0~]#awk’BEGIN{a[0]=”xiaohong”;a[1]=”xiaolan”;printa[0]}’xiaohong[root@tab0~]#awk

    2022年7月19日
    21
  • windows安装mysql8.0_windows7哪个版本功能最多

    windows安装mysql8.0_windows7哪个版本功能最多Windows系统Mysql8.0.28的安装教程

    2022年9月14日
    2
  • 概率论中的PDF,PMF,CDF是什么?

    概率论中的PDF,PMF,CDF是什么?http://blog.csdn.net/wzgbm/article/details/51680540

    2022年5月23日
    64
  • ssh sftp端口_sftp端口号是多少

    ssh sftp端口_sftp端口号是多少ssh/sftp默认端口是22.开通网络策略时,多会因为安全问题产生不便,所以需要修改端口。与其说是修改,不如说是增加,以增加2222端口为例。方法如下:修改ssh配置文件/etc/ssh/ssh_config及/etc/ssh/sshd_config将Port22前面的#放开,并在下面添加Port2222执行命令使配置生效servicesshdrestart检查是否生效sftp-P2222ip…

    2022年9月14日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号