This tutorials are based on the DirectX Tutorial, show how to set up IDE for using DirectX 9.
The basic Direct3D Program, includes four basic steps:
// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")
// global declarations
LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
// function prototypes
void initD3D(HWND hWnd); // sets up and initializes Direct3D
void render_frame(void); // renders a single frame
void cleanD3D(void); // closes Direct3D and releases memory
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface
D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information
ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear out the struct for use
d3dpp.Windowed = TRUE; // program windowed, not fullscreen
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D
// create a device class using this information and information from the d3dpp stuct
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
}
Create a function to render a frame
// this is the function used to render a single frame
void render_frame(void)
{
// clear the window to a deep blue
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
d3ddev->BeginScene(); // begins the 3D scene
// do 3D rendering on the back buffer here
d3ddev->EndScene(); // ends the 3D scene
d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame
}
Create a function to close Direct3D
// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
d3ddev->Release(); // close and release the 3D device
d3d->Release(); // close and release Direct3D
}
You can get the complete codes from Github
If you run this program you should get something like this:
fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。
输入
输入包括多行。
每行是一个字符串,长度不超过200。
一行的末尾与下一行的开头没有关系。
输出
输出包含多行,为输入按照描述中变换的结果。
样例输入
The Marshtomp has seen it all before.
marshTomp is beaten by fjxmlhx!
AmarshtompB
样例输出
The fjxmlhx has seen it all before.
fjxmlhx is beaten by fjxmlhx!
AfjxmlhxB
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
int main() {
string str, temp;
const string s1 = "marshtomp";
const string s2 = "fjxmlhx";
string::size_type a = s1.size();
string::size_type b = s2.size();
while (getline(cin, temp)) {
str = temp;
transform(str.begin(),str.end(),str.begin(),::tolower);
string::size_type pos = 0;
while ((pos=str.find(s1,pos))!=string::npos) {
str.replace(pos, a, s2);
temp.replace(pos,a,s2);
pos+=b;
}
cout << temp << endl;
}
return 0;
}
Give you two integers P and Q. Let all divisors of P be X-coordinates. Let all divisors of Q be Y-coordinates.
For example, when P=6 and Q=2, we can get the coordinates (1,1) (1,2) (2,1) (2,2) (3,1) (3,2) (6,1) (6,2).
You should print all possible coordinates in the order which is first sorted by X-coordinate when coincides, sorted by Y-coordinate.
输入
One line with two integers P and Q(1 <= P, Q <= 10000).
输出
The output may contains several lines , each line with two integers Xi and Yi, denoting the coordinates.
样例输入
6 2
样例输出
1 1
1 2
2 1
2 2
3 1
3 2
6 1
6 2
#include <iostream>
#include <vector>
using namespace std;
int main () {
int p, q;
while (cin >> p >> q) {
vector<int> arr1, arr2;
for (int i=1; i<=p; i++)
if (p % i==0)
arr1.push_back(i);
for (int i=1; i<=q; i++)
if (q % i==0)
arr2.push_back(i);
for (int m=0; m<arr1.size(); m++)
for (int n=0; n<arr2.size(); n++)
cout << arr1[m] << " " << arr2[n] << endl;
}
return 0;
}
给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期)。
只有闰年有2月29日,满足以下一个条件的年份为闰年:
年份能被4整除但不能被100整除
年份能被400整除
输入
第一行为一个整数T,表示数据组数。
之后每组数据包含两行。每一行格式为”month day, year”,表示一个日期。month为{“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November” , “December”}中的一个字符串。day与year为两个数字。
数据保证给定的日期合法且第一个日期早于或等于第二个日期。
输出
对于每组数据输出一行,形如”Case #X: Y”。X为数据组数,从1开始,Y为答案。
数据范围
1 ≤ T ≤ 550
小数据:
2000 ≤ year ≤ 3000
大数据:
2000 ≤ year ≤ 2×109
样例输入
4
January 12, 2012
March 19, 2012
August 12, 2899
August 12, 2901
August 12, 2000
August 12, 2005
February 29, 2004
February 29, 2012
样例输出
Case #1: 1
Case #2: 0
Case #3: 1
Case #4: 3
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int n;
cin >> n;
int startDay, endDay, startYear, endYear;
char startMonth[20], endMonth[20];
int i = 1;
while (n--) {
int count = 0;
scanf("%s %d, %d", startMonth, &startDay, &startYear);
scanf("%s %d, %d", endMonth, &endDay, &endYear);
if (strcmp(startMonth, "February")!= 0 && strcmp(startMonth, "January")!= 0)
startYear++;
if ((strcmp(endMonth, "February")== 0 && endDay<29) || strcmp(endMonth, "January")== 0)
endYear--;
count = (endYear / 4 - endYear / 100 + endYear / 400) - (startYear / 4 - startYear / 100 + startYear / 400);
if ((startYear%4==0 && startYear%100 !=0) || (startYear%400 ==0))
count++;
cout << "Case #" << i << ": " << count << endl;
i++;
}
return 0;
}
A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Given a string consisting of only lower case letters, output all its lucky non-empty substrings in lexicographical order. Same substrings should be printed once.
输入
A string consisting no more than 100 lower case letters.
输出
Output the lucky substrings in lexicographical order, one per line. Same substrings should be printed once.
样例输入
aabcd
样例输出
a
aa
aab
aabc
ab
abc
b
bc
bcd
c
cd
d
#include <iostream>
#include <string>
#include <set>
#include <unordered_map>
using namespace std;
int table[11] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89};
int main() {
string input;
cin >> input;
const int n = input.size();
set<string> res;
unordered_map<char, int> map;
string curr;
for (int i=0; i<n; i++) {
for (int j=1; j+i<= n; j++) {
curr = input.substr(i, j);
int count = 0;
for (int k=0; k<curr.size(); k++) {
if (map[curr[k]]==0) {
count++;
map[curr[k]] =1;
}
}
for (int m=0; m<11; m++) {
if (count == table[m]) {
res.insert(curr);
break;
}
else if (count <table[m])
break;
}
map.clear();
}
}
set<string>::iterator it = res.begin();
while (it!=res.end()) {
cout << *it << endl;
it++;
}
return 0;
}