| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 484 人关注过本帖
标题:有关读取txt文档并对其进行搜索的问题!
取消只看楼主 加入收藏
fredcao
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-9-30
收藏
 问题点数:0 回复次数:2 
有关读取txt文档并对其进行搜索的问题!
给一个包含如下列文档的的txt文件
每行后面的数字代表 从1900 到2000 年的11 个数字

A 83 140 228 286 426 612 486 577 836 0 0
Aaliyah 0 0 0 0 0 0 0 0 0 380 215
Aaron 193 208 218 274 279 232 132 36 32 31 41
Abagail 0 0 0 0 0 0 0 0 0 0 958
Abbey 0 0 0 0 0 0 0 0 537 451 428
。。。。。。

输出结果类似这样

请输入一个名字:A
字母为:A
第一次出现次数:83
第二次出现次数:140
第三次出现次数:228


已经分出4个array,但是查询方程不会了,下面是我的code,请帮忙看一下,谢谢


using System;

namespace FirstName
{
    class MainClass
    {
        static void ReadData(string filename, out string[] Names,
                             out string[] Decade1980, out string[] Decade1990, out string[] Decade2000)
        {
            string input;
             file;

            file = new (filename);

            input = file.ReadLine();        // open file, read first line to get N, parse it:

            int N;
            N = int.Parse (input);
                                    
            Names = new string[N];  // create the arrays:
            Decade1980 = new string[N];
            Decade1990 = new string[N];
            Decade2000 = new string[N];

            input = file.ReadLine();

            for (int i = 0; i < N; i++)
            {
                string[] values;
                values = input.Split ();

                Names [i] = values[0];
                Decade1980[i] = values[9];
                Decade1990[i] = values[10];
                Decade2000[i] = values[11];

                input = file.ReadLine();
            }

            file.Close ();
        
        }





        static void IsNameExist(string word, string[] Names, string[] Decade1980, string[] Decade1990,
                                string[] Decade2000)
        {
            int i;
            i = 0;

            while (i < Names.Length)
            {
                if (Names [i] == word)
                {   

                    Console.WriteLine ("Name: " + Names [i]);
                    Console.WriteLine ("Popularity in 1980: " + Decade1980 [i]);
                    Console.WriteLine ("Popularity in 1990: " + Decade1990 [i]);
                    Console.WriteLine ("Popularity in 2000: " + Decade2000 [i]);
               
                }
                else
                {

                    Console.WriteLine (">> Search failed: " + "'" + word + "'" + "was not found");

                }

            }



        }








        static void Main(string[] args)
        {
            Console.WriteLine ("** Name Popularity Program **");
            Console.WriteLine ();

            string[] Names;
            string[] Decade1980;
            string[] Decade1990;
            string[] Decade2000;

            ReadData ("firstnames.txt", out Names,
                      out Decade1980, out Decade1990, out Decade2000);

            string word;
            Console.Write (">>Please enter a first name to search for: ");
            word = Console.ReadLine ();   

        
            IsNameExist (word, Names, Decade1980, Decade1990, Decade2000);
        
               


            Console.Write (">>Please enter a first name to search for: ");
            word = Console.ReadLine ();

            Console.WriteLine ();
            Console.WriteLine ("** Bye **");

        }

    }

}
搜索更多相关主题的帖子: 字母 
2013-09-30 12:48
fredcao
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-9-30
收藏
得分:0 
主要是中间那部分查询不知该怎么做?
2013-09-30 12:49
fredcao
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-9-30
收藏
得分:0 
没人帮忙看看吗?
2013-09-30 23:55
快速回复:有关读取txt文档并对其进行搜索的问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042123 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved