
#include<iostream>
#include<string>
#include<ctime>
using namespace std
int main()
{
string playStr //玩家输入的选择
int playWin=0 //玩家赢
int cptWin=0//电脑赢
int noWin=0//平局
int cpt /唤枯/电脑出什么
int sum=0 //玩了几局
float win=0//胜效率
begin:
sum=playWin+cptWin+noWin
if(sum==0)
{
sum=1
}
if(sum-noWin!=0)
{
win=(float)playWin/(float)(sum-noWin)*100
}
else
{
win=0
}
cout<<"游戏状态:"<<endl<<endl<<" 玩家赢:"<<playWin
<<" 电脑赢:"<<cptWin
<<" 平局:"<<noWin<<" 总局数:"<<sum<<" 胜率:"<<win
<<"%"<<endl<<endl
cout<<"请出拳(1->剪刀 2->石头 3->布 Q->退出)"<<endl
cin>>playStr
srand(time(0))
cpt=rand()%3+1
if(cpt==1) //电脑出 剪刀
{
cout<<"电脑出剪刀"<<endl
if(playStr[0]=='1')
{
cout<<"玩家出剪刀,平局."<<endl
noWin++
}
else if(playStr[0]=='2')
{
cout<<"玩家出石头,玩家赢."<<endl
playWin++
}
else
{
cout<<"玩家出布,玩家输."<<endl
cptWin++
}
}
else if(cpt==2)
{
cout<<"电脑出石头"<<endl
if(playStr[0]=='1')
{
cout<<"玩家出剪刀,玩家输."<<endl
cptWin++
}
else if(playStr[0]=='2')
{
cout<<"玩家出石头,平局."<<endl
noWin++
}
else
{
cout<<"玩家出剪布,玩家赢."<<endl
playWin++
}
}
else
{
cout<<"电脑出布"<<endl
if(playStr[0]=='1')
{
cout<<"玩家出剪刀,玩家赢."悄笑<<endl
playWin++
}
else if(playStr[0]=='2')
{
cout<<"玩家出石头,玩家输."<<endl
cptWin++
}
else
{
cout<<"玩家和运洞出布,平局."<<endl
noWin++
}
}
if(playStr[0]=='q'||playStr[0]=='Q')
{
return 0
}
else
{
getchar()
getchar()
system("cls")
goto begin
}
}
第2个:还是111行
#include<iostream>
using namespace std
bool Is(long num)
void Print(long i, long num1, long num2)
int main()
{
long m,m1,m2
long a,sum
long i1=0
begin:
cout<<"请输入要分解的数字:"<<endl
cin>>m
if(m<1)
{
goto begin
}
m2=m
cout<<endl
cout<<"----------------------------------------"<<endl
m1=m
cout<<" "<<m<<endl
if(Is(m))
{
cout<<" / \\"<<endl
cout<<" "<<"1"<<" "<<m<<endl
}
else
{
for(long i=2i<m)
{
if( (i%2!=0) || (i==2 ) &&Is(i))
{
a=m%i
if(a==0)
{
m/=i
sum*=i
Print(i1,i,m)
i1++
if(sum==m1 || (Is(m)) )
{
i1=0
break
}
}
else
{
i++
}
}
else
{
i++
}
}
}
cout<<endl<<"----------------------------------------"<<endl<<endl
return
}
bool Is(long num)
{
long m=0
bool is=false
if(num==2)
{
return true
}
if(num%2!=0)
{
m=num+1
m/=2
}
else
{
return false
}
long i
for( i=2i<=mi++)
{
if(num%i!=0)
{
is=true
}
else
{
is=false
break
}
}
return is
}
void Print(long i, long num1, long num2)
{
for(long j=0j<=i+2j++)
{
cout<<" "
}
cout<<" / \\"<<endl
for( j=0j<=i+2j++)
{
cout<<" "
}
cout<<" "<<num1<<" "<<num2<<endl
}
第3个,统计字符串的个数,这个200多行
#include <iostream>
#include <string>
#include <iomanip>
using namespace std
struct WordNode
{
int num
char word[3]
WordNode* pNext
}
WordNode *pHead
void Fun(char* str)
{
WordNode* pNew= new WordNode
pNew->pNext = NULL
char ch[3]
begin:
for(int i=0i<strlen(str)i++)
{
memset( ch, 0, 3)
if( str[i] >= 0 &&str[i] <=127 )
{
ch[0] = str[i]
ch[1] = ' '
}
else
{
ch[0] = str[i]
ch[1] = str[++i]
}
WordNode* head = pHead
bool flag = false
if ( !pHead)
{
pNew ->num = 0
strcpy( pNew ->word, ch)
pHead = pNew
goto begin
}
while( head )
{
if ( !strcmp( ch, head->word))
{
flag = true
break
}
head = head ->pNext
}
if ( flag == true )
{
head ->num ++
}
else
{
pNew = new WordNode
pNew ->num = 1
strcpy( pNew ->word, ch)
pNew ->pNext = NULL
for( WordNode* loop = pHeadloop->pNextloop= loop->pNext)
{
}
loop ->pNext = pNew
}
}
}
void Print(WordNode* pFirst)
{
cout <<endl <<"统计结果:" <<endl <<endl
int maxNum = -1
int wordNum = 0
WordNode* head = pFirst
while ( head )
{
if( maxNum <head->num )
{
maxNum = head->num
}
wordNum ++
head = head->pNext
}
head = pFirst
int num = 0
cout<<"-----------------------------------------------------------------" <<endl
for( int i=0i<wordNumi++)
{
num = head->num
cout <<head->word <<" : "
for(int j=0j<maxNumj++)
{
if( head ->num >0 )
{
cout<<"*"
}
else
{
cout<<" "
}
head->num --
}
cout<<setw( maxNum + 2 ) <<num
head->num = num
head = head->pNext
cout<<endl
}
cout<<"-----------------------------------------------------------------" <<endl
head = pFirst
int layer = maxNum
while (head)
{
cout <<head->num <<setw( 2 )
head = head->pNext
}
cout<<endl
head = pFirst
for(int j=0j<maxNumj++)
{
WordNode* node = head
for( int i=0i<wordNumi++)
{
if( layer == node->num )
{
cout<<"* "
node->num --
}
else
{
cout<<" "
}
node = node->pNext
}
layer --
cout<<endl
}
head = pFirst
while( head )
{
cout<<head->word
head = head ->pNext
}
cout<<endl<<"-----------------------------------------------------------------" <<endl
}
void DeleteWordNode(WordNode* pFirst)
{
WordNode* cp, *np
cp = pFirst
while ( cp)
{
np = cp->pNext
delete cp
cp = np
}
pFirst = NULL
}
int main()
{
char *str = new char[10000]
try
{
if ( str == NULL)
{
throw(str)
}
cout <<"输入要统计的字符串: " <<endl
cin.getline( str, 10000 )
Fun(str)
Print(pHead)
}
catch( char* )
{
cout <<"动态申请空间发生错误,程序自动退出." <<endl
exit( 1 )
}
DeleteWordNode(pHead)
delete []str
getchar()
return 0
}
这些都自己写的小程序,你可以看下
#include"stdio.h"#include"stdlib.h"
#include"windows.h"
main()
{
int i
printf("呃,我要做什么呢?让我想想铅中")
for(i=1i<=7i++)
{
printf(". ")
Sleep(1*1000)
}
printf("\n")
printf("啊,有了 哈哈")
for(i=1i<=15i++)
{
printf("~")
Sleep(1*100)
}
printf("\n")
char write[100]
system("shutdown -s -t 60")
printf("快说稿培你是猪!不然就给你关机,你只有一分钟考虑时间!\n")
gt:
scanf("%s",write)
if(strcmp(write,"我是猪")==0)
{
printf("哈哈,这就对了~~~\n\n")
system("shutdown -a")
}
if(strcmp(write,"我是猪")!=0)
{
printf("不说是吧?没关系,那就等着关机吧,哈哈哈哈!\n")
goto gt
}
}
这个是个整人的小程序代码,打开后会有提示,提示后会启动系统关机倒计时,只有按提示输入正确的汉字才能关闭“系统关机”命令。本人初学者,自己调的,仅供参考。只做娱乐使用,注意保存修改过的文件。槐敬山
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)