中兴笔试程序题

article/2025/8/25 16:57:03

文本编辑器(15

要求: 

1)编辑文本;

2)保存、打开指定位置的文本文件;

3)具有输入输出界面。

代码:(此代码在vc6.0中运行是正确的,在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.写入文本"<<endl;cout<<"2.读文本"<<endl;cout<<"3.退出程序"<<endl;cout<<"请选择:";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<<"输入错误!"<<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) {// 按先序次序输入二叉树中结点的值(一个字符),空格字符表示空树,// 构造二叉链表表示的二叉树T。char ch;cin >> ch;if (ch == '#')T = NULL;else {if (!(T = (TreeNode *)malloc(sizeof(TreeNode))))return 0;T->data = ch;              // 生成根结点CreateBiTree(T->left);   // 构造左子树CreateBiTree(T->right);   // 构造右子树}return T;
} // CreateBiTreevoid 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.二维平面上有若干点,求出一条直线能穿越最多的点

#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;elsereturn -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;elsek[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 ;
}
思路:分别求出其中一点与其它点的直线的斜率,进行排序,如果斜率相同则同一条直线。

#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 != '\0'){while(*qStr != *pStr){num = 0;qStr++;}while(*qStr == *pStr && *pStr !='\0' && *qStr !='\0'){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;
}



http://chatgpt.dhexx.cn/article/XICcAJgg.shtml

相关文章

中兴2016校招软件在线笔试题

面试经验可以参考我的另一篇文章&#xff0c;是7月初参加openday面试的&#xff0c;文章链接http://blog.csdn.net/dandelion1314/article/details/47009585 招聘群里有人发的招聘时间安排&#xff0c;仅供参考。 据说今年是中兴的第一次在线笔试&#xff0c;摄像头监控&am…

MeasureSpec的理解和详尽源码分析

package cc.ww;import android.view.View; import android.view.View.MeasureSpec; import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.MarginLayoutParams; import android.widget.LinearLayout;/*** author http://blog.csdn.net/lfdfhl* * 文档描…

自定义View 测量过程(Measure)

目录 一、作用二、储备知识2.2 ViewGroup.LayoutParams2.3 MeasureSpec 三、measure过程详解3.1 单一View的measure过程具体流程源码分析源码总结 3.2 ViewGroup的measure过程测量原理具体流程源码分析流程总结 四、总结 一、作用 测量View的宽 / 高 在某些情况下&#xff0c;…

Android MeasureSpec解析

1. MeasureSpec组成 MeasureSpec是View的一个内部类&#xff0c;由一个32位的int值组成&#xff0c;前两位代表SpecMode测量模式&#xff0c;后30位代表SpecSize大小值。 其中测量模式共有三种&#xff1a; EXACTLY&#xff08;确定&#xff09;&#xff1a;父控件为子View指…

使用View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED)在在onCreate中获得控件的大小问题

android 在onCreate中获得控件的大小 int w View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED); int h View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED); edt_height.measure(w, h); int height edt_height.getMeasuredHeight(); int w…

MeasureSpec中三种模式:UNSPECIFIED,AT_MOST,EXACTLY

在自定义View和ViewGroup的时候&#xff0c;我们经常会遇到int型的MeasureSpec来表示一个组件的大小&#xff0c;这个变量里面不仅有组件的尺寸大小&#xff0c;还有大小的模式。 这个大小的模式&#xff0c;有点难以理解。在系统中组件的大小模式有三种&#xff1a; 1.精确模式…

评测指标(metrics)

评测指标(metrics) metric主要用来评测机器学习模型的好坏程度,不同的任务应该选择不同的评价指标, 分类,回归和排序问题应该选择不同的评价函数. 不同的问题应该不同对待,即使都是 分类问题也不应该唯评价函数论,不同问题不同分析. 回归(Regression) 均方误差(MSE) (1) l ( y…

MeasureSpec学习—对Integer.MAX_VALUE 2的认识

在自定义View和ViewGroup的时候&#xff0c;我们经常会遇到int型的 MeasureSpec 来表示一个组件的大小&#xff0c;这个变量里面不仅有组件的尺寸大小&#xff0c;还有大小的模式。 这个大小的模式&#xff0c;有点难以理解。在系统中组件的大小模式有三种&#xff1a; 1.精确…

理解Android中的MeasureSpec

文章收藏的好句子&#xff1a;永远要相信美好的事情即将发生。 ps&#xff1a;本文源码是基于 Android Api 31 来分析的 目录 1、MeasureSpec 1、1 SpecMode 1、2 MeasureSpec 的 int 值和 LayoutParams 的对应关系 1、MeasureSpec 我们在 Android 手机上看到的界面&#xff0c…

android Measurespec测量模式

MeasureSpecs 类 1、是一个32位的二进制数&#xff0c;由模式&#xff08;mode&#xff09;和大小&#xff08;size&#xff09;组成&#xff0c; 2、其中&#xff1a;32和31位代表测量模式&#xff08;mode&#xff09;、后30位代表测量大小&#xff08;size&#xff09; 3、…

MeasureSpec源码解读

文章目录 MeasureSpec的源码MeasureSpec与LayoutParams 今天来讲讲MeasureSpec吧。因为他与View的测量流程相关性很大&#xff0c;只有正确的理解了MeasureSpec的工作原理&#xff0c;我们才能更好的自定义View。那么MeasureSpec它的作用是什么呢&#xff1f;一般来说&#xff…

理解 MeasureSpec

在开始本篇文章之前&#xff0c;我们先看一段代码&#xff1a; Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int expendSpec MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);super.onMeasure(widthMe…

对MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE 2, MeasureSpec.AT_MOST)的一点理解

之前 遇到ScrollView中嵌入ListView&#xff0c;GridView冲突的解决&#xff08;让ListView全显示出来&#xff09; 链接 网上查找资料&#xff0c;代码大致如下&#xff1a; import android.content.Context; import android.util.AttributeSet; import android.widget.ListV…

View的基本概念与MeasureSpec

1.基本概念 View的绘制是由measuer、layout、draw三个过程才能完整的绘制一个View&#xff0c;其中measure是测量View的宽、高&#xff0c;layout是为了确认View在父容器所在的位置&#xff0c;draw是负责在屏幕上将View绘制出来。View的绘制流程是从ViewRoot的performTraversa…

Android之:了解MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE 2,MeasureSpec.AT_MOST)

在自定义View和ViewGroup的时候&#xff0c;我们经常会遇到int型的 MeasureSpec 来表示一个组件的大小&#xff0c;这个变量里面不仅有组件的尺寸大小&#xff0c;还有大小的模式。 这个大小的模式&#xff0c;有点难以理解。在系统中组件的大小模式有三种&#xff1a; 1.精确…

Android开发 MeasureSpec介绍

搬家后的博客链接: IT客栈 www.itkezhan.org 在自定义View和ViewGroup的时候&#xff0c;我们经常会遇到int型的MeasureSpec来表示一个组件的大小&#xff0c;这个变量里面不仅有组件的尺寸大小&#xff0c;还有大小的模式。 这个大小的模式&#xff0c;有点难以理解。在系统中…

Android-测量规格(MeasureSpec)

目录 一、简介二、组成三、具体使用 一、简介 二、组成 测量规格(MeasureSpec)是由测量模式(mode)和测量大小(size)组成&#xff0c;共32位(int类型)&#xff0c;其中&#xff1a; 测量模式(mode)&#xff1a;占测量规格(MeasureSpec)的高2位&#xff1b;测量大小(size)&…

MeasureSpec学习 - 转

在自定义View和ViewGroup的时候&#xff0c;我们经常会遇到int型的 MeasureSpec 来表示一个组件的大小&#xff0c;这个变量里面不仅有组件的尺寸大小&#xff0c;还有大小的模式。 这个大小的模式&#xff0c;有点难以理解。在系统中组件的大小模式有三种&#xff1a; 1.精确…

MeasureSpec介绍

在自定义View和ViewGroup的时候&#xff0c;我们经常会遇到int型的MeasureSpec来表示一个组件的大小&#xff0c;这个变量里面不仅有组件的尺寸大小&#xff0c;还有大小的模式。 这个大小的模式&#xff0c;有点难以理解。在系统中组件的大小模式有三种&#xff1a; 1.精确模式…

Android 中MeasureSpec的创建规则

概述 在Android中&#xff0c;View的onMeasure()方法用来对控件进行测量&#xff0c;确定控件的宽高。该方法的两个参数widthMeasureSpec和heightMeasureSpec由父View计算后传入子view的measure()方法&#xff0c;再由子view的measure()方法传入onMeasure()方法&#xff0c;本…