Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions 201731062422/wordcount/wordcount.psess
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<VSPerformanceSession Version="1.00">
<Options>
<Solution>wordcount.sln</Solution>
<CollectionMethod>Sampling</CollectionMethod>
<AllocationMethod>None</AllocationMethod>
<AddReport>true</AddReport>
<ResourceBasedAnalysisSelected>true</ResourceBasedAnalysisSelected>
<UniqueReport>Timestamp</UniqueReport>
<SamplingMethod>Cycles</SamplingMethod>
<CycleCount>10000000</CycleCount>
<PageFaultCount>10</PageFaultCount>
<SysCallCount>10</SysCallCount>
<SamplingCounter Name="" ReloadValue="00000000000f4240" DisplayName="" />
<RelocateBinaries>false</RelocateBinaries>
<HardwareCounters EnableHWCounters="false" />
<EtwSettings />
<PdhSettings>
<PdhCountersEnabled>false</PdhCountersEnabled>
<PdhCountersRate>500</PdhCountersRate>
<PdhCounters>
<PdhCounter>\Memory\Pages/sec</PdhCounter>
<PdhCounter>\PhysicalDisk(_Total)\Avg. Disk Queue Length</PdhCounter>
<PdhCounter>\Processor(_Total)\% Processor Time</PdhCounter>
</PdhCounters>
</PdhSettings>
</Options>
<ExcludeSmallFuncs>true</ExcludeSmallFuncs>
<InteractionProfilingEnabled>false</InteractionProfilingEnabled>
<JScriptProfilingEnabled>false</JScriptProfilingEnabled>
<PreinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PreinstrumentEvent>
<PostinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PostinstrumentEvent>
<Binaries>
<ProjBinary>
<Path>wordcount\obj\Debug\wordcount.exe</Path>
<ArgumentTimestamp>01/01/0001 00:00:00</ArgumentTimestamp>
<Instrument>true</Instrument>
<Sample>true</Sample>
<ExternalWebsite>false</ExternalWebsite>
<InteractionProfilingEnabled>false</InteractionProfilingEnabled>
<IsLocalJavascript>false</IsLocalJavascript>
<IsWindowsStoreApp>false</IsWindowsStoreApp>
<IsWWA>false</IsWWA>
<LaunchProject>true</LaunchProject>
<OverrideProjectSettings>false</OverrideProjectSettings>
<LaunchMethod>Executable</LaunchMethod>
<ExecutablePath>wordcount\bin\Debug\wordcount.exe</ExecutablePath>
<StartupDirectory>wordcount\bin\Debug\</StartupDirectory>
<Arguments>
</Arguments>
<NetAppHost>IIS</NetAppHost>
<NetBrowser>InternetExplorer</NetBrowser>
<ExcludeSmallFuncs>true</ExcludeSmallFuncs>
<JScriptProfilingEnabled>false</JScriptProfilingEnabled>
<PreinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PreinstrumentEvent>
<PostinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PostinstrumentEvent>
<ProjRef>{ECAC8591-371E-4446-9CB6-BF7BD733D65B}|wordcount\wordcount.csproj</ProjRef>
<ProjPath>wordcount\wordcount.csproj</ProjPath>
<ProjName>wordcount</ProjName>
</ProjBinary>
</Binaries>
<Reports>
<Report>
<Path>wordcount190404.vspx</Path>
</Report>
</Reports>
<Launches>
<ProjBinary>
<Path>:PB:{ECAC8591-371E-4446-9CB6-BF7BD733D65B}|wordcount\wordcount.csproj</Path>
</ProjBinary>
</Launches>
</VSPerformanceSession>
22 changes: 22 additions & 0 deletions 201731062422/wordcount/wordcount.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wordcount", "wordcount\wordcount.csproj", "{ECAC8591-371E-4446-9CB6-BF7BD733D65B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ECAC8591-371E-4446-9CB6-BF7BD733D65B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECAC8591-371E-4446-9CB6-BF7BD733D65B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECAC8591-371E-4446-9CB6-BF7BD733D65B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECAC8591-371E-4446-9CB6-BF7BD733D65B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added 201731062422/wordcount/wordcount.v12.suo
Binary file not shown.
6 changes: 6 additions & 0 deletions 201731062422/wordcount/wordcount/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
119 changes: 119 additions & 0 deletions 201731062422/wordcount/wordcount/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;

namespace Wordcount
{
class count
{
int cnum = 0;
int lines = 0;
public int charcount(string txt)
{
char[] txt1 = txt.ToArray();/*接受字符放入数组*/
for (int i = 0; i < txt1.Length; i++)
{
if (txt1[i] >= 0 && txt1[i] <= 127)
cnum++;
}
return cnum;

}
public int linescount(string txt)//得到文本行数
{
var path = txt;
char[] txt1 = txt.ToArray();
using (var sr = new StreamReader(path))
{
var ls = "";
while ((ls=sr.ReadLine())!=null)
{
lines++;
}
}
return lines;
}
public void wordcount(string text)//得到单词个数及前十词频单词
{
Dictionary<string, int> dic = new Dictionary<string, int>();
StreamReader sr = new StreamReader(text);
string line = sr.ReadLine();
line = line.ToLower();
string[] wordArr = null;
int num = 0;
while (!sr.EndOfStream)
{

wordArr = line.Split(' ');
foreach (string s in wordArr)
{
if (s.Length == 0)
continue;
//去除标点
line = Regex.Replace(line, @"[\p{P}*]", "", RegexOptions.Compiled);
//将单词加入dic表中
if (dic.ContainsKey(s))
{
num = Convert.ToInt32(dic[s]) + 1;
dic[s] = num;
}
else
{
dic.Add(s, 1);
}
}
line = sr.ReadLine();
}

ArrayList wordList = new ArrayList(dic.Keys);
//对Hashtable中的Keys按字母序排列
wordList.Sort();
//按次数进行插入排序【稳定排序】,所以相同次数的单词依旧是字母序
string tmp = String.Empty;
int valueTmp = 0;
for (int i = 1; i < wordList.Count; i++)
{
tmp = wordList[i].ToString();
valueTmp = dic[wordList[i].ToString()];//次数
int j = i;
while (j > 0 && valueTmp > (int)dic[wordList[j - 1].ToString()])
{
wordList[j] = wordList[j - 1];
j--;
}
wordList[j] = tmp;//j=0
}
//打印出来
Console.WriteLine("word:{wordList.Count}");
foreach (object item in wordList)
{
Console.WriteLine((string)item + ":" + (int)dic[item.ToString()]);
}
}
}
class Program
{
static void Main(string[] args)
{
count cc = new count();
string gettext = Console.ReadLine();//输入文本地址
string text = @gettext;
if (!File.Exists(text))
{
Console.WriteLine("文件不存在!");
return;
}
string txt = File.ReadAllText(@text);
//将字符数与行数打印出来
Console.WriteLine("characters:" + cc.charcount(txt));
Console.WriteLine("lines:" + cc.linescount(text));
cc.wordcount(text);
Console.ReadKey();
}
}
}
36 changes: 36 additions & 0 deletions 201731062422/wordcount/wordcount/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("wordcount")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("wordcount")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("82bf474c-d012-490b-a1bd-237248c59fa4")]

// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="c:\program files (x86)\microsoft visual studio 12.0\team tools\static analysis tools\fxcop\Xml\CodeAnalysisReport.xsl"?>
<FxCopReport Version="12.0">
<Localized>
<String Key="Category">类别</String>
<String Key="Certainty">确定性</String>
<String Key="CollapseAll">全部折叠</String>
<String Key="CheckId">检查 ID</String>
<String Key="Error">错误</String>
<String Key="Errors">错误</String>
<String Key="ExpandAll">全部展开</String>
<String Key="Help">帮助</String>
<String Key="Line">行</String>
<String Key="Messages">消息</String>
<String Key="LocationNotStoredInPdb">[位置未存储在 Pdb 中]</String>
<String Key="Project">项目</String>
<String Key="Resolution">解析</String>
<String Key="Rule">规则</String>
<String Key="RuleFile">规则文件</String>
<String Key="RuleDescription">规则说明</String>
<String Key="Source">源</String>
<String Key="Status">状态</String>
<String Key="Target">目标</String>
<String Key="Warning">警告</String>
<String Key="Warnings">警告</String>
<String Key="ReportTitle">代码分析报告</String>
</Localized>
</FxCopReport>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
c:\users\ddn\documents\visual studio 2013\Projects\wordcount\wordcount\bin\Debug\wordcount.exe.config
c:\users\ddn\documents\visual studio 2013\Projects\wordcount\wordcount\bin\Debug\wordcount.exe
c:\users\ddn\documents\visual studio 2013\Projects\wordcount\wordcount\bin\Debug\wordcount.pdb
c:\users\ddn\documents\visual studio 2013\Projects\wordcount\wordcount\obj\Debug\wordcount.csprojResolveAssemblyReference.cache
c:\users\ddn\documents\visual studio 2013\Projects\wordcount\wordcount\obj\Debug\wordcount.exe
c:\users\ddn\documents\visual studio 2013\Projects\wordcount\wordcount\obj\Debug\wordcount.pdb
C:\Users\DDN\Documents\Visual Studio 2013\Projects\wordcount\wordcount\bin\Debug\wordcount.exe.CodeAnalysisLog.xml
C:\Users\DDN\Documents\Visual Studio 2013\Projects\wordcount\wordcount\bin\Debug\wordcount.exe.lastcodeanalysissucceeded
Binary file not shown.
Binary file not shown.
Binary file not shown.
58 changes: 58 additions & 0 deletions 201731062422/wordcount/wordcount/wordcount.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{ECAC8591-371E-4446-9CB6-BF7BD733D65B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>wordcount</RootNamespace>
<AssemblyName>wordcount</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading