求3个100行左右的C语言程序 要代码 无限感谢!!!!
3个回答
展开全部
第1个,<剪刀石头布>,111行
#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=2; i<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=2; i<=m; i++)
{
if(num%i!=0)
{
is=true;
}
else
{
is=false;
break;
}
}
return is;
}
void Print(long i, long num1, long num2)
{
for(long j=0; j<=i+2; j++)
{
cout<<" ";
}
cout<<" / \\"<<endl;
for( j=0; j<=i+2; j++)
{
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=0; i<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 = pHead; loop->pNext; loop= 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=0; i<wordNum; i++)
{
num = head->num;
cout << head->word <<" : " ;
for(int j=0; j<maxNum; j++)
{
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=0; j<maxNum; j++)
{
WordNode* node = head;
for( int i=0; i<wordNum; i++)
{
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<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=2; i<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=2; i<=m; i++)
{
if(num%i!=0)
{
is=true;
}
else
{
is=false;
break;
}
}
return is;
}
void Print(long i, long num1, long num2)
{
for(long j=0; j<=i+2; j++)
{
cout<<" ";
}
cout<<" / \\"<<endl;
for( j=0; j<=i+2; j++)
{
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=0; i<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 = pHead; loop->pNext; loop= 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=0; i<wordNum; i++)
{
num = head->num;
cout << head->word <<" : " ;
for(int j=0; j<maxNum; j++)
{
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=0; j<maxNum; j++)
{
WordNode* node = head;
for( int i=0; i<wordNum; i++)
{
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 <malloc.h>
#define null 0
typedef struct bitnode{
char date;
struct bitnode *lchild,*rchild;
}bitnode,*bittree;
typedef struct qnode
{bittree data;
struct qnode *next;
}qnode,*queueptr;
typedef struct
{queueptr front;
queueptr rear;
}linkqueue;
bitnode *creatbittree()
{bitnode *t;
char ch;
scanf("%c",&ch);
if(ch=='*')t=null;
else
{
t=(bitnode *)malloc(sizeof(bitnode));
t->date=ch;
t->lchild=creatbittree();
t->rchild=creatbittree();
}return t;
}
void preordertraverse(bitnode *t)
{if(t)
{printf("%c",t->date);
preordertraverse(t->lchild);
preordertraverse(t->rchild);}
else printf("*");
}
int treehigh(bitnode *t)
{int lh,rh,h;
if(t==null)
h=0;
else{
lh=treehigh(t->lchild);
rh=treehigh(t->rchild);
h=(lh>rh ? lh:rh)+1;
}
return h;
}
void exchange(bittree t)
{bittree p;
if(t!=null)
{p=t->lchild;
t->lchild=t->rchild;
t->rchild=p;
exchange(t->lchild);
exchange(t->rchild);
}
}
int initqueue(linkqueue *q)
{q->front=q->rear=(queueptr)malloc(sizeof(qnode));
if(q->front)return 1;
else return 0;
q->front->next=null;
}
void enqueue(linkqueue *q,bittree e)
{queueptr p;
p=(queueptr)malloc(sizeof(qnode));
p->data=e;
p->next=null;
q->rear->next=p;
q->rear=p;
}
int queueempty(linkqueue *q)
{if(q->front==q->rear)return 1;
else return 0;}
bittree dequeue(linkqueue *q)
{bittree e;
queueptr p;
if(q->front!=q->rear){
p=q->front->next;
e=p->data;
q->front->next=p->next;
if(q->rear==p)q->rear=q->front;
free(p);
return e;
}
}
void layerorder(bittree t)
{int i;
bittree p;
linkqueue *k;
k=(linkqueue *)malloc(sizeof(linkqueue));
initqueue(k);
enqueue(k,t);
while(!(i=queueempty(k)))
{p=dequeue(k);
printf("%c",p->data);
if(p->lchild)enqueue(k,p->lchild);
if(p->rchild)enqueue(k,p->rchild);
}
}
main()
{
bitnode *p;
int h;
p=null;
printf("\nplease enter the bittree nodes:");
p=creatbittree();
printf("root-lift-right output:");
preordertraverse(p);
h=treehigh(p);
printf("\ntree high :%d\n",h);
exchange(p);
printf("After exchang,root-lift-right output:");
preordertraverse(p);
printf("\nThe level output:");
layerorder(p);
}
#include <malloc.h>
#define null 0
typedef struct bitnode{
char date;
struct bitnode *lchild,*rchild;
}bitnode,*bittree;
typedef struct qnode
{bittree data;
struct qnode *next;
}qnode,*queueptr;
typedef struct
{queueptr front;
queueptr rear;
}linkqueue;
bitnode *creatbittree()
{bitnode *t;
char ch;
scanf("%c",&ch);
if(ch=='*')t=null;
else
{
t=(bitnode *)malloc(sizeof(bitnode));
t->date=ch;
t->lchild=creatbittree();
t->rchild=creatbittree();
}return t;
}
void preordertraverse(bitnode *t)
{if(t)
{printf("%c",t->date);
preordertraverse(t->lchild);
preordertraverse(t->rchild);}
else printf("*");
}
int treehigh(bitnode *t)
{int lh,rh,h;
if(t==null)
h=0;
else{
lh=treehigh(t->lchild);
rh=treehigh(t->rchild);
h=(lh>rh ? lh:rh)+1;
}
return h;
}
void exchange(bittree t)
{bittree p;
if(t!=null)
{p=t->lchild;
t->lchild=t->rchild;
t->rchild=p;
exchange(t->lchild);
exchange(t->rchild);
}
}
int initqueue(linkqueue *q)
{q->front=q->rear=(queueptr)malloc(sizeof(qnode));
if(q->front)return 1;
else return 0;
q->front->next=null;
}
void enqueue(linkqueue *q,bittree e)
{queueptr p;
p=(queueptr)malloc(sizeof(qnode));
p->data=e;
p->next=null;
q->rear->next=p;
q->rear=p;
}
int queueempty(linkqueue *q)
{if(q->front==q->rear)return 1;
else return 0;}
bittree dequeue(linkqueue *q)
{bittree e;
queueptr p;
if(q->front!=q->rear){
p=q->front->next;
e=p->data;
q->front->next=p->next;
if(q->rear==p)q->rear=q->front;
free(p);
return e;
}
}
void layerorder(bittree t)
{int i;
bittree p;
linkqueue *k;
k=(linkqueue *)malloc(sizeof(linkqueue));
initqueue(k);
enqueue(k,t);
while(!(i=queueempty(k)))
{p=dequeue(k);
printf("%c",p->data);
if(p->lchild)enqueue(k,p->lchild);
if(p->rchild)enqueue(k,p->rchild);
}
}
main()
{
bitnode *p;
int h;
p=null;
printf("\nplease enter the bittree nodes:");
p=creatbittree();
printf("root-lift-right output:");
preordertraverse(p);
h=treehigh(p);
printf("\ntree high :%d\n",h);
exchange(p);
printf("After exchang,root-lift-right output:");
preordertraverse(p);
printf("\nThe level output:");
layerorder(p);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你要的这3个100行左右的C语言程序是做什么要的?你自己不说清楚点,我们想帮你也帮不上啊!~!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询