c语言节日

c语言节日,第1张

一个字典结构.c++用标准库

或者用字符串查找.

===例子嘛,我以前宽告写的一个英汉对照的程序(相当粗糙的),框架可以套用.

======main.cpp

#include <iostream>

#include <fstream>

#include <string>

#include <vector>

#include <iomanip>

const int MAXNUM=100

using namespace std

struct lst_w

{

string en

string cn

}

class Compare_lst_w_en

{

public:

int operator()(const lst_w&l1,const lst_w&l2) const {

return l1.en<l2.en

}

}

void trans(char*)

void trans(string)

string null_str("NULL")

string&get(string)

vector<lst_w>li(MAXNUM)

int main()

{

ifstream fi("list.txt")

string str

int tmp

int i=0

while(!fi.eof())

{

getline(fi,str)

tmp=str.find(':')

li[i].en=str.substr(0,tmp)

li[i].cn=str.substr(tmp+1,string::npos)

if(li[i].en!="")

//cout.width(9)

//cout<<li[i].en<<"慎茄明 翻译为:"<<纳告li[i].cn<<endl

i++

}

fi.close()

ofstream fo("list.txt")

sort(li.begin(),li.begin()+i,Compare_lst_w_en())

for(int j=0j<ij++)

{

fo<<li[j].en<<":"<<li[j].cn<<endl

}

fo.close()

//getline(cin,str)

//trans(str)

trans("i catch your dog that injure their leg")

//cout<<i

getchar()

}

void trans(char* cstr)

{

string str(cstr)

return trans(str)

}

void trans(string str)

{

//string str(cstr)

string word

string enl,cnl

int n=-1

int old_n=0

n=str.find(' ')

while(n!=-1)

{

word=str.substr(old_n,n-old_n)

int sp=word.size() - get(word).size()

if(sp>0){

enl+=word

enl+=" "

cnl+=get(word)

cnl+=string(1+sp,' ')

}else

{

enl+=word

enl+=string(1-sp,' ')

cnl+=get(word)

cnl+=" "

}

old_n=n+1

n=str.find(' ',old_n)

}

word=str.substr(old_n,string::npos)

if(word!="")

{

enl+=word

cnl+=get(word)

}

cout<<enl<<endl

cout<<cnl<<endl

}

string&get(string instr)

{

int i

for(i=0i<li.size()i++)

{

if(li[i].en==instr)

return li[i].cn

}

return null_str

}

=======list.txt

a:一

aback:向后

abacus:算盘

abalone:鲍鱼

abandon:放弃

abase:使受辱

abash:使羞愧

abate:使变小

abattoir:屠宰场

abbess:女修道院长

abbey:大修道院

abbot:男修道院长

abbreviate:缩写

abdicate:退离

abdomen:腹

abduct:诱拐

abed:在床上

aberrant:异常的

aberratiton:失常

abet:怂恿

am:是

an:一

and:和

animal:动物

are:是

bit:位

cat:猫

catch:抓住

chameleon:变色龙

computer:计算机

dictionary:字典

dog:狗

edit:编辑

end:结束

extinct:灭绝

file:文件

fine:好的

good:好

he:他

i:我

injure:受伤

is:是

it:它

leg:脚

list:列表

mine:我的

my:我的

of:的

one:一

or:或

plus:加

run:跑

she:她

sky:天

start:开始

system:系统

that:那

their:他们的

they:他们

two:二

word:词

you:你

your:你的

zero:零

游戏规则:烟花从地上飞上天空,然后绽放,最后落下消失。

第一步

添加一个城市的背景

第二步

创建烟花Rocket角色,做出八个造型

第一个造型命名为C1,代表升空的烟花。当这个小红点C1到达某个随机的位置,再将它切换到其他七个造型之一,这样就模拟中岁激出烟花绽放的雀纯效果。在加一些简单的图形效果让整个过程更加真实。

烟花程序如下:

开始将自己隐藏,然后重复执行卖袜,每隔一个随机时间创建一个克隆体。由于原角色是隐藏的,所以它的克隆体一开始都是隐藏的。

克隆体程序如下:

扩展

还可以将y坐标增加-1和将亮度特效增加-3模拟出烟花缓缓下降并逐渐消失的效果。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12359318.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-23
下一篇2023-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存