From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a4d2751f9487bd38 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-07 11:52:39 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!spool.news.uu.net!not-for-mail Date: Mon, 07 Jul 2003 14:52:03 -0400 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5a) Gecko/20030611 Thunderbird/0.1a X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Real data for a change in the assignment operators and Bounded_String discussions. References: <3F04F778.5090305@attbi.com> <1057585611.821825@master.nyc.kbcfp.com> <3F09999F.1040206@attbi.com> In-Reply-To: <3F09999F.1040206@attbi.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1057603924.174628@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1057603924 15423 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:40114 Date: 2003-07-07T14:52:03-04:00 List-Id: Robert I. Eachus wrote: > I originally posted a working Ada program, with output. Would you care > to do the same for your C and/or C++ versions? Sorry about that. I read your code too hastily and misinterpreted what it was doing. Here we go - #include #include #include #include #include #include template Out copy_if(In b, In e, Out o, Pred p) { for (; b != e; ++b) if (p(*b)) *o++ = *b; return o; } void process(std::istream &in, std::ostream &out) { typedef std::vector buf_type; buf_type buf; copy_if(std::istream_iterator(in), std::istream_iterator(), std::back_inserter(buf), isdigit); buf_type::iterator b = buf.begin(), e = buf.end(); unsigned long c1d[10] = { 0 }, c2d[10][10] = { 0 }; out << "There were " << buf.size() << " digits.\n\n"; while (b != e) { char d = *b++ - '0'; ++c1d[d]; if (b != e) ++c2d[d][*b - '0']; } for (int i = 0; i < 10; ++i) out << i << "=" << std::setw(3) << c1d[i] << " "; out << "\n\n"; for (int j = 0; j < 10; ++j) { for (int i = 0; i < 10; ++i) out << j << i << "=" << std::setw(3) << c2d[j][i] << " "; out << "\n"; } } int main(int c, char **v) { std::ifstream is; if (c > 1) is.open(v[1]); std::ofstream os; if (c > 2) os.open(v[2]); process(is.is_open() ? is : std::cin, os.is_open() ? os : std::cout); }