**床前明月_ ,疑是地_霜,举头望_月,低头思故_。 **
**A.光 上 明 乡 **
**B.上 明 乡 光 **
**C.乡 上 明 光 **
**D.光 乡 上 明 **
**请你编写一函数,随机扣掉每一句的一个字,然后生成3个错误选项,一个正确选项,选项的字必须是诗里所缺的字。请写出数据结构,算法。 **
\#include "stdafx.h"\
\#include \<tchar.h\>\
int randInt( int low, int high ){\
return rand()%(high+1-low) + low;\
}\
void Output( wchar\_t \*words, int \*idices, int n ){\
setlocale(LC\_ALL,"chs");\
for( int i = 0; i \< n; i++ )\
std::wcout \<\< words[idices[i]] \<\< " ";\
std::wcout \<\< endl;\
}\
int main(){\
const wchar\_t \*wStr = L"床前明月光,疑是地上霜.举头望明月,低头思故乡.";\
wchar\_t words[4];\
\
srand( static\_cast\<unsigned\>(time(NULL)) );\
// 提取每句的其中一个字.\
for( int i = 0; i \< 4; i++ )\
words[i] = wStr[randInt(6\*i,6\*i+4)];\
\
// 通过0、1、2、3四个下标随机出words的四个选项.\
// 其中必须包含一个正确选项,其下标为{0,1,2,3}.\
// 也就是随机三个不同的选项出来就行了.\
int idices[4] = { 0, 1, 2, 3 };\
Output( words, idices, 4 );\
\
for( int i = 0; i \< 3; i++ ){\
std::swap( idices[i], idices[randInt(i,3)] );\
Output( words, idices, 4 );\
}\
}
// 唉,不是均匀的随机排列.