找回密码
 加入
搜索
查看: 2484|回复: 7

今天面试用的 au3 实现的面试题

  [复制链接]
发表于 2016-1-14 16:07:43 | 显示全部楼层 |阅读模式
玩了这么久 au3 也算给别人普及一下。
题目是有一个 10W 行数据的文本,要求拆分该文件为 10 个均等的文件快,比如第一个文件存放 1~10000,第二个文件存放 10001~20000,以此类推。
我简单的实现如下步骤。

1、算文件行数
2、load 到内存当作数组处理
3、遍历数组按 10W 行一个文件写到不同的文件里。

第二个题目是字符串替换,一个很长的字符串,把其中的子字符串替换掉。我就写了一句 strreplace。。。

第三个题是在一个文本中查找 email 地址,写了一个正则。
发表于 2016-1-14 16:43:58 | 显示全部楼层
还好没让你写个操作系统
偷偷的问一句?有没有被潜规则?
 楼主| 发表于 2016-1-14 17:37:00 | 显示全部楼层
回复 2# haijie1223


    哈哈,我先来把你潜了
发表于 2016-1-15 07:32:08 | 显示全部楼层
回复 3# nmgwddj


    你把我当成什么人了,哥只卖身不卖艺
 楼主| 发表于 2016-1-15 22:51:53 | 显示全部楼层
回复 4# haijie1223


    用 C 做了一下第一题,瞬间感觉 au3 各种高大上。。。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int _FileCountLines(const char* strFileName);

int main(int argc, char* argv[])
{
        int nCountLine = _FileCountLines("C:/test.txt");
        printf("File count lines = %d\n", nCountLine);

        FILE* pFile = NULL;
        fopen_s(&pFile, "C:/test.txt", "r");

        int nSubFileName = 1;
        // save new file name "10.txt\n"
        char sSubFileName[7] = { 0 };
        // save read old file data "100000\n"
        char sReadBuffer[7] = { 0 };
        for (size_t i = 0; i < nCountLine; i += nCountLine / 10)
        {
                FILE* pSubFile = NULL;
                // new file name append .txt
                _itoa_s(nSubFileName, sSubFileName, 10);
                strcat_s(sSubFileName, ".txt");
                // open new file at current directory
                fopen_s(&pSubFile, sSubFileName, "w+");
                if (NULL == pSubFile) return -1;

                // read old file and write data to new file step nCountLine / 10
                for (size_t x = i; x < i + nCountLine / 10; x++)
                {
                        fgets(sReadBuffer, sizeof(sReadBuffer), pFile);
                        fputs(sReadBuffer, pSubFile);
                        memset(sReadBuffer, 0, sizeof(sReadBuffer));
                }

                memset(sSubFileName, 0, sizeof(sSubFileName));
                // file name ++
                nSubFileName++;
                // close new file
                fclose(pSubFile);
        }

        fclose(pFile);
        system("pause");
        return 0;
}

int _FileCountLines(const char* strFileName)
{
        int lines = 0;
        int ch;
        FILE* pFile = NULL;

        fopen_s(&pFile, strFileName, "r");
        if (NULL == pFile) return -1;

        
        while ((ch = fgetc(pFile)) != EOF)
        {
                if (ch == '\n')
                {
                        lines++;
                }
        }

        fclose(pFile);
        return lines;
}
发表于 2016-1-21 15:23:38 | 显示全部楼层
很是不得了啊!
发表于 2016-1-21 23:39:50 | 显示全部楼层
au3就是调用api的,底层还是c写的
发表于 2016-1-25 15:59:05 | 显示全部楼层
赞一个,非常强大
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-26 14:33 , Processed in 0.078453 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表