wordcount(代码片段)

blogchw blogchw     2023-01-09     419

关键词:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;


namespace WordCount

    class Program
    
        static void Main(string[] args)
        
            Type type = new Type();
            Count count = new Count();

            int ctr;
            int Operand;
            string theword = "";
            int ope1, ope2, ope3;
            ope1 = ope2 = ope3 = 0;

            theword += string.Format(args[1]);

            if(args.Length>2)
            
                Console.WriteLine("读取出错");
            
            else
            
                type.ope = args[0];

                for(ctr = 0; ctr < args.Length; ctr++)
                
                    theword += string.Format("参数 0 为:1
", ctr + 1, args[ctr]);
                             
            

            Operand = type.ChooseType();

            if(Operand==1)
            
                ope1 = count.countchar(args[1]);
                theword += string.Format("总字符数为:0", ope1);
            
            else if(Operand==2)
            
                ope2 = count.countword(args[1]);
                theword += string.Format("总单词数为:0", ope2);
            
            else if(Operand==3)
            
                ope3 = count.countLine(args[1]);
                theword += string.Format("总行数为:0", ope3);
            
            else
            
                Console.WriteLine("读取出错");
            

            CreatFile creatFile = new CreatFile();
            creatFile.Write(theword);
        
         

type类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WordCount

    class Type
    
        public string ope;
        public int ChooseType()
        
            if (ope == "-c")
            
                return 1;
            
            else if (ope == "-w")
            
                return 2;
            
            else if (ope == "-l")
            
                return 3;
            
            else
                return 0;
        
    

count类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace WordCount

    class Count
    
        Open open = new Open();//将open类实例化
        public int countchar(string filename)
        
            open.LoadFile(filename);
            int charcounter = 0;
            int nChar;

            while ((nChar = open.sr.Read()) != -1)
            
                charcounter++;     // 统计字符数
            
            Console.WriteLine("字符数为:" + charcounter);//显示字符总数

            open.sr.Close();
            open.fs.Close();
            return charcounter;
        

        public int countword(string filename)
        
            open.LoadFile(filename);
            int nChar;
            int wordcounter = 0;
            char[] symbol =   , 	, ,, ., ?, !, :, ;, , =,
                              ", 
, , , (, ), +, -, * ;
            //间隔符
            while ((nChar = open.sr.Read()) != -1)
            
                foreach (char c in symbol)
                
                    if (nChar == (int)c)
                    
                        wordcounter++; // 统计单词数
                    
                
            
            Console.WriteLine("单词数为:" + wordcounter);//显示单词总数

            open.sr.Close();
            open.fs.Close();
            return wordcounter;
        

        public int countLine(string filename)
        
            open.LoadFile(filename);
            string line;
            int Linecounter = 0;//记录行数

            //当当前行不为空,即当前行存在,即 +1 
            while ((line = open.sr.ReadLine()) != null)
            
                Linecounter++;
            
            Console.WriteLine("总行数为:" + Linecounter);//显示行数

            //关闭文件
            open.sr.Close();
            open.fs.Close();

            return Linecounter;
        

    

create类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace WordCount

    class CreatFile
    
        public void Write(string theword)
        
            FileStream fs = new FileStream("outputFile.txt", FileMode.Create);
            //获得字符串
            byte[] data = System.Text.Encoding.Default.GetBytes(theword);
            //开始写入
            fs.Write(data, 0, data.Length);
            //清空缓冲区、关闭流
            fs.Flush();
            fs.Close();
        
    

open类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace WordCount

    class Open
    
        public StreamReader sr;
        public FileStream fs;

        public void LoadFile(string fileName)
        
            Encoding encoder = Encoding.GetEncoding("GB2312");
            fs = new FileStream(fileName, FileMode.Open);
            sr = new StreamReader(fs, encoder);

        
    




输入错误的指令就会报错
技术分享图片

技术分享图片

 

 

 

wordcount(代码片段)

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.IO;namespaceWordCountclassProgramstaticvoidMain(string[]args)Typetype=newType() 查看详情

wordcount(代码片段)

1.Github项目地址https://github.com/chaindreamjet/WordCount2.PSP表格PSP2.1PSP阶段预估耗时(分钟)实际耗时(分钟)Planning计划 20 30·Estimate·估计这个任务需要多少时间 20 30Development开发 700 940·Analysis·需求分析(包括 查看详情

mapreduce编写wordcount程序代码实现(代码片段)

MapReduce经典案例代码(wordcount)以经典的wordcount为例,通过自定义的mapper和reducer来实现单词计数packagecom.fwmagic.mapreduce;importorg.apache.hadoop.conf.Configuration;importorg.apache.hadoop.fs.Path;importorg.apache.hadoop.io. 查看详情

分享知识-快乐自己:运行(wordcount)案例(代码片段)

运行wordcount案例:一):大数据(hadoop)初始化环境搭建二):大数据(hadoop)环境搭建三):运行wordcount案例四):揭秘HDFS五):揭秘MapReduce六):揭秘HBase七):HBase编程-----------------------------------------------------------------Hadoo... 查看详情

wordcount(代码片段)

一.码云地址https://i.cnblogs.com/EditPosts.aspx?opt=1https://gitee.com/lttzy/wordcount二.PSP表格PSP2.1PSP阶段预估耗时(分钟)实际耗时(分钟)Planning计划 30 20·Estimate·估计这个任务需要多少时间 20 10Development开发 45 查看详情

wordcount(代码片段)

一.github:https://github.com/JiejieCM/WordCount二.pspPSP2.1PSP阶段预估耗时(分钟)实际耗时(分钟)Planning计划 30 30·Estimate·估计这个任务需要多少时间3030Development开发 3天 5天·Analysis·需求分析(包括学习新技术) 2天&nbs... 查看详情

wordcount(代码片段)

WordCount一.个人Gitee地址:https://gitee.com/godcoder979/(该项目完整代码在这里) 二.项目简介:该项目是一个统计文件字符、单词、行数等数目的应用程序,通过输入命令来执行你想要的操作。所用语言:java命令格式:wc.exe[para]&... 查看详情

wordcount(代码片段)

一、Gitee项目地址https://gitee.com/YSS_MYGit/WordCount二、基本思路 我看到项目后,首先想到的是使用C#语言编写,因为我对C#语言比较熟悉些。此项目有两个类,一个是Program类,该类是程序的入口,主要用于传参,另一个是WC类,... 查看详情

wordcount(代码片段)

一.Gitee地址:https://gitee.com/zjgss99/WordCount 二.项目分析:对程序设计语言源文件统计字符数、单词数、行数,统计结果以指定格式输出到默认文件中,以及其他扩展功能,并能够快速地处理多个文件。命令格式:wc.exe[para] ... 查看详情

个人项目wordcount(代码片段)

1.项目GitHub地址:https://github.com/FPXBao/wordcount2.解题思路:分析程序基本需求,将其功能分为三个函数调用:主函数intmain();功能函数Ccount();Wcount();Lcount();并进行相关知识学习。3.代码说明:主函数:#include<stdio.h>#include<stdlib.... 查看详情

wordcount(代码片段)

   码云地址:https://gitee.com/qaqxx88/wc1WordCount需求说明 (1)对源文件进行字符数,行数,单词数的统计并且放在与wc.exe相同目录下的result.txt中  (2)基本功能  wc.exe -c file.c   &nbs 查看详情

wordcount基础功能(代码片段)

Gitte地址:https://gitee.com/gyuyue/WordCount PSP表格PSP2.1PSP阶段预估耗时(分钟)实际耗时(分钟)Planning计划 15 20·Estimate·估计这个任务需要多少时间 30 30Development开发 60 80·Analysis·需求分析(包括学习新技术)... 查看详情

wordcount代码实现及测试(代码片段)

...者:201631062515201631062415码云地址:https://gitee.com/heshuxiang/WordCount/tree/master2.项目需求  对程序设计语言源文件统计字符数、单词数、行数,统计结果以指定格式输出到默认文件中,以及其他扩展功能,并能够快速地处理多... 查看详情

wordcount基本功能(代码片段)

项目的gitee地址:https://gitee.com/ITtoto/WordCount 开发语言:C语言PSP2.1表格PSP2.1PSP阶段预估耗时(分钟)实际耗时(分钟)Planning计划20 16·Estimate·估计这个任务需要多少时间 30 27Development开发 120 160·Analysis·需... 查看详情

wordcount(代码片段)

   Gitee地址:https://gitee.com/dyh1621838953/WordCount1此项目我只实现了基本功能,即字符、行数、单词数的计算以及将结果输出到文件中。该项目用C#语言进行实现。解题思路:   根据题目要求所知,需要读取一... 查看详情

[mapreduce_1]运行wordcount示例程序(代码片段)

 0.说明  MapReduce实现WordCount示意图&& WordCount代码编写    1. MapReduce实现WordCount示意图     1.Map:预处理阶段,将原始数据映射成每个K-V,发送给reduce  2.Shuffle:混洗(分类),将相同的Key... 查看详情

wordcount(代码片段)

gitee地址:https://gitee.com/yzyindex/wordcount需求分析通过程序设计,编写一个可执行文件exe能够对源程序文件进行统计字符数、单词数、行数,统计结果可以以指定的格式输出到默认文件中。可执行程序命名为:wc.exe,该程序处理用... 查看详情

wordcount-软测作业(代码片段)

1.github地址 https://github.com/zgwe/wordCount2.PSP2.1PSP阶段预估耗时实际耗时(分钟)(分钟)Planning计划 10 10·Estimate·估计这个任务需要多少时间 20 10Development开发 40 60·Analysis·需求分析(包括学习新技术)  查看详情