ZTE's written examination procedure questions

Source: Internet
Author: User

Text editors (15)

Requirements:

(1) Edit the text;

(2) Save and open the text file at the specified location;

(3) has the input and output interface.

Code: (This code is correct to run in vc6.0 and is not compiled in vs2010)

#include <fstream.h> #include <string.h> #include <iostream.h> #include <stdio.h> #include <
	stdlib.h> void input () {char str[100];
	Ofstream out ("D:\\test.txt");
		
	if (!out) {cout<< "Cannot open output file.\n";
	} cout<< "Please input:" <<endl;
	Gets (str);
	out<<str;
	cout<<endl;
	
Out.close ();
	void output () {Ifstream in ("D:\\test.txt");
		
	if (!in) {cout<< "Cannot open input file.\n";
	} char str;
	while (In.get (str)) {cout<<str;
	} cout<<endl;
In.close ();
    } void Main () {int j=1;
    Char i[10];	
	int n;
		do {cout<< "1. Write text" <<endl;
		cout<< "2. Read Text" <<endl;
		cout<< "3. Exit program" <<endl;
		cout<< "Please choose:";
		cin>>i; if ((i[0]<49) | |
		(i[0]>51)) {cout<< "Input error!!"
			<<endl;
		Goto end;
        else n=i[0]-48;
			Switch (n) {case 1:input ();
		Break
			Case 2:output ();
		Break
		Case 3:exit (0); Default:cout<< "Input Error!"
		<<endl;
	} end:;
}while (j==1); }

2

.

#include <iostream> #include <cstdio> using namespace std;
	struct TreeNode {char data;
	TreeNode *left;
TreeNode *right;

};
	void GetHeight (TreeNode *t, int &h) {if (T = = NULL) H = 0;
		else {int left_h;
		GetHeight (T->left, Left_h);
		int right_h;
		GetHeight (T->right, Right_h);
	H = 1 + max (Left_h, Right_h);
	} TreeNode *createbitree (TreeNode *&t) {//Enter the value of the node in the binary tree in order of precedence (one character), empty characters represents an empty tree,//construct the two-fork tree T represented by the two-fork list.
	Char ch;
	CIN >> ch;
	if (ch = = ' # ') T = NULL; else {if (!) (
		T = (TreeNode *) malloc (sizeof (TreeNode))) return 0;              T->data = ch;   Generating root node Createbitree (t->left);   Construction of left subtree Createbitree (t->right);
Construct right subtree} return T;

	}//Createbitree void free (TreeNode *&t) {if (T = = NULL) return;
	Free (t->left);
	T->left = NULL;
	Free (t->right);
	T->right = NULL;
	Free (T);
T = NULL;
	int main () {TreeNode *t = NULL;

	Createbitree (T);
	int height;
	GetHeight (T, height); cout <<
	Height << Endl;

	Free (T);
return 0; }

3. A number of points on the two-dimensional plane, to find a line that can travel through the most points

#include <iostream> using namespace std;
const double inf=2100000000;
struct point {int x,y;};
    int cmp (const void *a, const void *b) {if (* (double*) a> * (double *) b) return 1;
else return-1;
Point p[1001];
Double k[1001];
    int main () {int N;
    int I,j,l,counter,ans;                            
                                         while (scanf ("%d", &n)!=eof && N) {for (i=0;i<n;i++)
                         scanf ("%d%d", &p[i].x,&p[i].y); for (ans=0,i=0;i<n-1;i++) {for (j=i+1,l=0;j<n;j++,l + +) {if (P[i].x==p[j].
                                                           x) K[l]=inf;
                                                  Else             K[l]=double (P[I].Y-P[J].Y)/(p[i].x-p[j].x);
                                         } qsort (K,l,sizeof (k[0]), CMP);
                                                           for (j=0;j<l;j++) {
                                                           Counter=1;
                                                                       while (J+1<l && k[j]==k[j+1]) {
                                                                       j + +;
                                                           counter++;
                                                                          } if (Counter>ans)
                                         Ans=counter; } printf ("%d/n", ans+1);
return 0; }
Train of thought: to find out the slope of one of the points and the other points, and to sort, if the same slope is the same line.

#include <iostream>
using namespace std;

void FindStr (char* str)
{
    if (str = NULL) return
        ;
    
    char* pstr = str;
    char* qstr = str+1;
    char* index = str;
    char* maxindex = str;
    int num = 0;
    int maxnum = 0;

    while (*pstr!= ' ")
    {while
        (*qstr!= *pstr) {
            num = 0;
            qstr++;
        }

        while (*qstr = = *pstr && *pstr!= ' i ' && *qstr '!= ')
        {
            num++;
            index = PSTR;
            qstr++;
            pstr++;
        }

        if (num>=1)
            index = index-num+1;
        if (num > Maxnum) {
            maxnum = num;
            Maxindex = index;
        }

        Qstr = pstr+1;
    }

    cout << "Result:";
    for (int i=0;i<maxnum;++i)
        cout << *maxindex++ << ";
    cout << Endl;
}


int main ()
{
    char* str = "ABCABCDABCD";
    FINDSTR (str); 

    return 0;
}


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.