C + + Sorts large amounts of data inside the text (shell,c++,fopen,awk,sed)

Source: Internet
Author: User
Tags bitset sorts

#/bin/bash# sort the data inside the text awk ' begin{rs= ', '}{print $0}end{} ' <a | Sort-n | Sed '/^$/d ' | awk ' begin{rs= ' \ n '; ors= ', '}{print $0}end{} ' |sed ' s/,$//g ' below is the C + + version. ----------------------------------------------------------------------#include <iostream> #include < Stdio.h> #include <stdlib.h>using namespace Std;template<int _n>class bitset{public:bitset () {_Tidy () ;//Call the _tidy () function to initialize all bits to 0.} void Show ()//displays 01 bits. {for (int _i=0;_i<_n;_i++) {cout<< (Test (_i)? ') 1 ': ' 0 ');}} BOOL Test (int _p)//tests whether the location is true (1). {int _i = _p/32;return (a[_i]>> (_p%32)) &0x1;} void _tidy () {for (int _i=0;_i<_w;_i++) {a[_i] = 0;}} void set (int _p)//sets the _p subscript to 1. {int _i = _P/32; A[_i] |= (0x1<< (_p%32));} void printf () {for (int _i=0;_i<_n;_i++) {test (_i) && (cout<<_i<< "");}} Prints the result of the arrangement. Private:typedef Long long;//is a unit array of 4 bytes long. enum{_nw= (_n-1)/(sizeof (long) *8), _w=_nw+1};int a[_w];}; Template<int _n>void deal_what (int &sum,char c,bitset<_n> &a,file *&out{if (c!= ' && c!= ', ' && c!= ' \ n ') {sum= (sum*10+ (c ' 0 ')); return;} Else{a.set (sum);//sets the data to the specified bit. }sum = 0;} Template<int _n>void get_result (bitset<_n> &a,file *&out) {int sum = 0;while (1) {char c = fgetc (out); if (c==eof) {return;} Deal_what<_n> (Sum,c,a,out);}} int get_value (int x,int &n)//number of digits {x && (N=get_value (x/10,n) +1); return n;} Template<int _n>void in_put (bitset<_n> &a,file *&in)//write results to file B.  {for (int _i=0;_i<_n;_i++) {if (A.test (_i)) {int _h=_i;int _k = 0;get_value (_h,_k); int flog = _k;int Save=0;while (1) {int Sum=1; for (int _j=_k;_j>0;_j--) {sum*=10;} char C = ((_h-save*sum)/(SUM/10)) + ' 0 '; Save = _h/(SUM/10); FPUTC (C,in); flog--; _k--;  if (flog==0) break;} FPUTC (", in);}}} int main () {FILE *out = fopen ("A", "A +");  FILE *in = fopen ("B", "A +"); Bitset<100> A;get_result (a,out); In_put (a,in); fclose (out); fclose (in);}

C + + Sorts large amounts of data inside the text (shell,c++,fopen,awk,sed)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.