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
Binary file added 201731062616/ConsoleApp2/.vs/ConsoleApp2/v15/.suo
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions 201731062616/ConsoleApp2/ConsoleApp2.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.438
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp2", "ConsoleApp2\ConsoleApp2.csproj", "{91A0E9F3-0CE3-4C7C-AF6A-EE93D64DBD86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{91A0E9F3-0CE3-4C7C-AF6A-EE93D64DBD86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91A0E9F3-0CE3-4C7C-AF6A-EE93D64DBD86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91A0E9F3-0CE3-4C7C-AF6A-EE93D64DBD86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91A0E9F3-0CE3-4C7C-AF6A-EE93D64DBD86}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC92EE05-1912-4B9D-BF7B-B5DFE2B0D7CC}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions 201731062616/ConsoleApp2/ConsoleApp2/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.6.1" />
</startup>
</configuration>
53 changes: 53 additions & 0 deletions 201731062616/ConsoleApp2/ConsoleApp2/ConsoleApp2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{91A0E9F3-0CE3-4C7C-AF6A-EE93D64DBD86}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleApp2</RootNamespace>
<AssemblyName>ConsoleApp2</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</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.Net.Http" />
<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" />
</Project>
148 changes: 148 additions & 0 deletions 201731062616/ConsoleApp2/ConsoleApp2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;

namespace ConsoleApp52
{
class zifu//统计字符数
{
public void A(string path)
{
int charcount = 0;
int nchar;
StreamReader sr = new StreamReader(path);
char[] symbol = { ' ', '\t', ',', '.', '?', '!', ':', ';', '\'', '\"', '\n', '{', '}', '(', ')', '+' ,'-',
'*', '='};
while ((nchar = sr.Read()) != -1)
{
charcount++;
}
Console.WriteLine("characters :{0}", charcount);

}

}
class word//统计字母数大于4的单词
{
int wordcount = 0;
public void B(string path)
{
string pattren = @"\s+|,\s*";
StreamReader sr = new StreamReader(path);
string line = sr.ReadToEnd();
Regex myregex = new Regex(pattren);
string[] output = myregex.Split(line);
foreach (string s in output)
{
if (s.Length > 3)
wordcount++;
}
Console.WriteLine("words :{0}", wordcount);

}

}
class line//统计行数
{

public void C(string path)
{
int linecount = 0;
string nchar;
StreamReader sr = new StreamReader(path);
while ((nchar = sr.ReadLine()) != null)
{

linecount++;

}
Console.WriteLine("line :{0}", linecount);

}

}
class Program
{
static void Main(string[] args)
{
string path = @"D:\git\WordCount\201731062616\ConsoleApp2\ConsoleApp2\bin\Debug\第三次作业.txt";
List<string> listnew = new List<string>();//所有单词放在listnew中
string pattren = @"\s+|,\s*";
StreamReader sr = new StreamReader(path);
string line = sr.ReadToEnd();
Regex myregex = new Regex(pattren);
string[] output = myregex.Split(line);
foreach (string s in output)
{
if (s.Length > 3)
listnew.Add(s);
}

zifu a = new zifu();
word b = new word();
line c = new line();
a.A(path);
b.B(path);
c.C(path);

Dictionary<string, int> keyValuePairs = new Dictionary<string, int>();
foreach (var word in listnew)
{
if (keyValuePairs.ContainsKey(word))
{
keyValuePairs[word]++;
}
else
{
keyValuePairs.Add(word, 1);
}
}
List<int> value = new List<int>();
foreach (var s in keyValuePairs.Values)
{
value.Add(s);
}
value.Sort((x, y) => -x.CompareTo(y));
int count = 0;
// Console.Write("频率:" + value[0] + " ");
foreach (var s in keyValuePairs)
{
if (s.Value.Equals(value[0]))
{
Console.WriteLine(s.Key + ":" + value[0]);
count++;
}
}

for (int i = 1; i < value.Count; i++)
{
if (count != 10)
{
if (value[i] == value[i - 1])
continue;
foreach (var s in keyValuePairs)
{
if (s.Value.Equals(value[i]))
{
if (count != 10)
{
Console.WriteLine(s.Key + ":" + value[i]);
count++;
}
else
break;
}
}
}
else
break;

}




}
}
}
36 changes: 36 additions & 0 deletions 201731062616/ConsoleApp2/ConsoleApp2/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("ConsoleApp2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP Inc.")]
[assembly: AssemblyProduct("ConsoleApp2")]
[assembly: AssemblyCopyright("Copyright © HP Inc. 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

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

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("91a0e9f3-0ce3-4c7c-af6a-ee93d64dbd86")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [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,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
Binary file not shown.
13 changes: 13 additions & 0 deletions 201731062616/ConsoleApp2/ConsoleApp2/bin/Debug/第三次作业.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
We all know that environment is so important to ourselves and our future generations. Natural resources have been depleted in an unprecedented scale. The environment ha
s been polluted in a way that never happened before. It is certain that the world and all the living organism on it are going straight to hell. But why those in power,
no matter how loud they speak out environmental protection, very few of them really care. The reason is simple. Human beings are greedy in nature. In ancient times, te
chnology is lacking, human beings did not have the right tool to exploit the nature on large scale. With industrial revolution and the development of science and techno
logy, these things can be achieved with relative ease. It can be said that the development of science can be a gospel and a curse on human race at the same time. It is
more than certain that the world is going straight to hell. Climate change comes at an unprecedented rate. We can see all the polar ice sheet melt in our own lifetime.
Cities by the sea will be flooded. Summer will get unbearably hot. Almost all the natural resources will be depleted. It is not that world leaders are unaware of this ,
but because of their greed no one is able to put the interest of the general public and future generations over their own pride. Development sounds an untouchable trut
h. Anything that comes in its way will be neglected. One thing that we never ponder is that the space and resources on this planet is limited which means that the raw
material and space for development is also limited. Now matter how great and intelligent human beings might be, we have our own weakness. The more intelligent a
creature is, the more physically vulnerable it is. With the worsening of the living environment, one can rarely predict that how many of us will eventually survive
this unprecedented change. It is time for us to think whether we should live in a more environmentally friendly manner so that our offsprings will also have space and
resources to live with or we just pamper ourselves to the extreme and forget about our future generation and the human race at large.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eb377b6b14e4ef154eb9357e15b38cc4e484fff8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
D:\git\WordCount\201731062616\ConsoleApp2\ConsoleApp2\bin\Debug\ConsoleApp2.exe.config
D:\git\WordCount\201731062616\ConsoleApp2\ConsoleApp2\bin\Debug\ConsoleApp2.exe
D:\git\WordCount\201731062616\ConsoleApp2\ConsoleApp2\bin\Debug\ConsoleApp2.pdb
D:\git\WordCount\201731062616\ConsoleApp2\ConsoleApp2\obj\Debug\ConsoleApp2.csprojAssemblyReference.cache
D:\git\WordCount\201731062616\ConsoleApp2\ConsoleApp2\obj\Debug\ConsoleApp2.csproj.CoreCompileInputs.cache
D:\git\WordCount\201731062616\ConsoleApp2\ConsoleApp2\obj\Debug\ConsoleApp2.exe
D:\git\WordCount\201731062616\ConsoleApp2\ConsoleApp2\obj\Debug\ConsoleApp2.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.