金山试题
來源:http://blog.pfan.cn/jixian/27083.html
?
typedef struct tagPOINT {?
??? ??? int x;
??? ??? int y;
??? } POINT
用變量var給出下面的定義
例:一個POINT 變量
答案:POINT var;
void ParseString(char* pstr);
要求:
例如:給定的字符串為:A,2.d?3!e4r87we79...
輸出結果為:Aderwe2348779,.?!...
如:給定整數131,其二進制表示為10000011,要求函數輸出以下結果:
1: 2
0: 5
1: 1
表示從最低位開始,包含2個1,5個0,1個1。
參考上一題,確定本函數的名字,入口出口及返回值,并實現本函數
HANDLE FindFirst(char* lpFileName);//用于查找給定目錄下是否有指定文件。若無則返回0,若有則返回一個句柄。例如:FindFirst("D:\\data\\*.txt")
BOOL FindNext(HANDLE hFindFile); //繼續查找該目錄下是否有其他匹配文件。
BOOL FindClose(HANDLE hFindFile);//用于結束查找。
利用上述API實現函數NumOfPicFiles,找出給定目錄下有多少個JPG及BMP文件(不考慮子目錄)。
int NumOfPicFiles(char*lpszfolder);
Lpszfolder表示指定目錄。
返回值表示找到的文件個數。
?
//此試題是金山在我學校招實習學生出的。
個人做的
2.vc6.0做的
#include<iostream>
using namespace std;
bool IsEven(int i);
int main()
{
?int n;
?cout<<"偶數返回1,其他返回0"<<endl;
?cout<<"input a int number:";
?cin>>n;
?cout<<IsEven(n)<<endl;
?
}
bool IsEven(int i)
{
?if(i>0)
?{
??if(i%2==0)
???return true;
??else
???return false;
?}
?else
?{
??cout<<"你輸入的為負數"<<endl;
??return false;
?}
}
3.//我用vs2005做的
#include<iostream>
using namespace std;
void ParseString(char* pstr);
bool checkzm(char zm);????? //判斷是不是字母
bool checksz(char sz);?? //判斷是否為數字
void out(char* pstr);
int main()
{
?/*char str[]="25abe!E@R6?9";*/
?cout<<"請輸入字符串"<<endl;
?char str[50];
?cin>>str;
?
?/*int n=(sizeof(str))/(sizeof(str[0]));*/
?cout<<"排序前"<<endl;
?out(str);
?ParseString(str);
?cout<<"排序后"<<endl;
?out(str);
? /*for(int i=0;i<n;i++)
?? cout<<str[i];
?? cout<<endl<<"排序后"<<endl;
? ParseString(str);
? for(int i=0;i<n;i++)
?? cout<<str[i];
? cout<<endl;*/
}
void ParseString(char* pstr)
{
?? int zmnum=0;???? //字母個數,也可以看作是已經排好序的字符個數
?? int n=0;???????? //跟蹤掃描的字符個數
?? char*pstr1=pstr;
?? for(;*pstr1;pstr1++) //掃描字符串,第一個for循環完成字母靠前
?? {
??? n++;
??? if(checkzm(*pstr1))
??? {
???? zmnum++;
???? char current=*pstr1; //獲取當前的字母
???? for(int i=n-2;i>=zmnum-1;i--)?????? //找到一個字母,就把它移動到前面去
???? {
????? *(pstr+i+1)=*(pstr+i);?????????? //向后移動其他字符
???? }
???? *(pstr+zmnum-1)=current;
??? }??
?? }
?? pstr1=pstr;
?? n=zmnum; //不再從第1個開始掃描了,字母已經放好了,從字母后面的字符開始掃描字符串
?
?? for(pstr1=pstr1+zmnum;*pstr1;pstr1++)????????????????????????? //第二個for循環完成數字在字母后面
?? {
??? n++;
??? if(checksz(*pstr1))
??? {???
???? zmnum++;???? //在這里不在指字母了,指排好序的字符個數
???? char current=*pstr1;
???? for(int i=n-2;i>=zmnum-1;i--)
???? {
?????? *(pstr+i+1)=*(pstr+i);?????????? //向后移動其他字符
???? }
???? *(pstr+zmnum-1)=current;
??? }
?? }
}
bool checkzm(char zm)?????? //判斷是不是字母
{
??? if((zm>='A' && zm<='z') || (zm>='a' && zm<='z'))
??return true;
?else
??return false;
}
bool checksz(char sz)?? //判斷是否為數字
{
?if(sz>='0' && sz<='9')
??return true;
?else
??return false;
}
void out(char* pstr)
{
?while(*pstr !='\0')
?{
??cout<<*pstr;
??pstr++;
?}
?cout<<endl;
}
4.//vs2005做的
#include<iostream>
using namespace std;
void ParseBinary(int);
int main()
{
?int n;
?cout<<"input a int number:";
?cin>>n;
?ParseBinary(n);
}
void ParseBinary(int n)
{
?int num=1;????? //計數
?int current; //當前位
?int pre;???? //當前的前一位
?for(int i=0;i<=7;i++)
?{
??
??
??if(n & (1 << i))
??{
???if(i==0)
???{
????pre=current=1;
???}
???current=1;
?//??cout<<"1 ";
??}
??else if(!(n & (1<<i)))
??{
???if(i==0)
???{?
????pre=current=0;
???}
???current=0;??
??//?cout<<"0 ";
??}
??if(i!=0)
??{
???if(pre==current)
????num++;
???else
???{
????cout<<pre<<" : "<<num<<endl;
????num=1;
????pre=current;
???}
??}
?}
?cout<<pre<<" : "<<num<<endl;
?
}
?
5.
//頭文件 stu.h
#ifndef STU_H
#define STU_H
#include<iostream>
#include<string>
using namespace std;
class student
{
private:
?string name;
?int year;
?int month;
?int day;
public:
?student(string name1,int year1,int month1,int day1)
?{
??name=name1;
??year=year1;
??month=month1;
??day=day1;??
?}
?void operator > (const student&student2)
?{
??if(year>=student2.year)?? //比較年
??{
???if(year>student2.year)
???{
????cout<<name<<",你年齡小于 "<<student2.name<<endl;
???}
???else //出生年相同
???{
????if(month>=student2.month)?????? //比較月
????{
?????if(month>student2.month)
?????{
??????cout<<name<<",你年齡小于 "<<student2.name<<endl;
?????}
?????else??? //出生月相同
?????{
??????if(day>=student2.day)
??????{
???????if(day>student2.day)
???????{
????????cout<<name<<",你年齡小于 "<<student2.name<<endl;
???????}
???????else?????????????????? //同一天出生,年齡相等
???????{
????????cout<<name<<",你年齡等于 "<<student2.name<<endl;
???????}
??????}
?????}
????}
???}
??}
??else
??{
???cout<<name<<",你年齡大于 "<<student2.name<<endl;
??}
?}
};
#endif
//.cpp文件,student.cpp
#include "stu.h"
#include<iostream>
using namespace std;
int main()
{
?student stu1("stu1",1985,6,7);
?student stu2("stu2",1986,6,5);
?stu1>stu2;
?
}
?
?
?
總結
- 上一篇: 苹果将阻止用户免费安装开测版iOS 17
- 下一篇: 中兴通讯已启动一轮人员优 涉及无线、终端