微軟實(shí)習(xí)生筆試題目最后一題
雖然咱被微軟給鄙視了,但是回來還是寫了寫最后一題的程序,
。當(dāng)時(shí)只有半個(gè)小時(shí),可我回來晃晃悠悠地寫也寫了起碼多于1個(gè)小時(shí)……看來咱跟微軟的要求差距還是蠻大的啊……哎……怨念……
// test.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//
#include "stdafx.h"
#define BUFMAX 100
//Find frequency of words of file-B.txt in file-A.txt
void Find (string &filenameA, string &filenameB)
{
string tempA, tempB;
char chA[BUFMAX], chB[BUFMAX];
int cnt = 0, match = 0;
if ( (filenameA.length()==0) || (filenameB.length()==0) )
{
cout << "Invalid input filename!" << endl;
return ;
}
ifstream infileA ( filenameA.c_str() );
ifstream infileB ( filenameB.c_str() );
if ( infileA.fail() || infileB.fail() )
{
cout << "Cannot open input files!" << endl;
return ;
}
while ( getline(infileB, tempB) )
{
memcpy ( chB, tempB.c_str(), tempB.length()+1 );
cnt = 0;
infileA.seekg (0, ios::beg);
while ( !infileA.eof() )
{
infileA >> tempA;
if (tempA == tempB)
cnt++;
else
{
memcpy (chA, tempA.c_str(), tempA.length()+1);
match = 1;
for (int i=0, j=0; ; i++, j++)
{
if (!chB[i] && !chA[j])
break;
else if ( !( chB[i] && chA[j] ))
{
match = 0;
break;
}
if (chB[i] == '?')
continue;
else if (chB[i] == '*')
for (;chA[j+1]!=chB[i+1];j++)
{
if (chA[j+1] == '\0')
break;
}
else if (chA[j] != chB[i])
{
match = 0;
break;
}
}
if (match)
cnt++;
}
}
cout << tempB << ' ' << cnt << endl;
}
infileA.close();
infileB.close();
}
int _tmain(int argc, _TCHAR* argv[])
{
string filenameA, filenameB;
cout << "Please input two files' name:" << endl;
cin >> filenameA >> filenameB;
Find (filenameA, filenameB);
return 0;
【微軟實(shí)習(xí)生筆試題目最后一題】相關(guān)文章:
有趣的微軟筆試題目08-05
微軟10道筆試面試題目08-24
微軟公司筆試經(jīng)驗(yàn)談和題目分析10-11
微軟筆試經(jīng)驗(yàn)分享10-30
騰訊實(shí)習(xí)生筆試題目07-09
騰訊實(shí)習(xí)生筆試題目09-20
筆試題目05-29
美的筆試的題目06-18
參加微軟的面試筆試經(jīng)驗(yàn)10-29
網(wǎng)易有道用戶產(chǎn)品實(shí)習(xí)生筆試題目08-14