#include "iostream"
#include "queue"
#include "stdio.h"
using namespace std;
#define Max 51
int Pre[Max],Mid[Max],N;
struct Node
{
int Data;
Node *Left;
Node *Right;
Node ()
{
Left=NULL;
Right=NULL;
}
};
void CreatTree(int PreLeft,int MidLeft,int Len,Node *&p)
{
if(Len<=0)
{
return ;
}
p=new Node;
p->Data=Pre[PreLeft];
int len,i=MidLeft;
while(Pre[PreLeft]!=Mid[i])
i++;
len=i-MidLeft;
CreatTree(PreLeft+1,MidLeft,len,p->Left);
CreatTree(PreLeft+len+1,i+1,Len-len-1,p->Right);
}
void Output(Node *p)
{
cout<<p->Data;
queue<Node *> Q;
if(p->Left!=NULL)
{
Q.push(p->Left);
}
if(p->Right!=NULL)
{
Q.push(p->Right);
}
while(!Q.empty())
{
Node *s=Q.front();
Q.pop();
cout<<" "<<s->Data ;
if(s->Left!=NULL)
{
Q.push(s->Left);
}
if(s->Right!=NULL)
{
Q.push(s->Right);
}
}
}
void Swap(Node *p )
{
if(p==NULL) return;
Swap(p->Left);
Swap(p->Right);
Node *s;
s=p->Left;
p->Left=p->Right;
p->Right=s;
}
int main()
{
//freopen("1.txt","r",stdin);
cin>>N;
Node *Tree;
Tree=NULL;
int i,j;
for(i=1;i<=N;i++)
{
cin>>Mid[i];
}
for(j=1;j<=N;j++)
{
cin>>Pre[j];
}
CreatTree(1,1,N,Tree);
Swap(Tree);
Output(Tree);
cout<<endl;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int t,i,a,b;
scanf("%d:%d",&a,&b);
if(a<12&&a>=0)
{
printf("Only hh:mm. Too early to Dang.");
}
if(a==12&&b==0)
{
printf("Only hh:mm. Too early to Dang.");
}
else
{
if(b>0)
{
for(i=0;i<=a-12;i++)
{
printf("Dang");
}
}
else
{
for(i=0;i<a-12;i++)
{
printf("Dang");
}
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c,d,e,f,n,i=1,t,r,q;
char m;
scanf("%d %d",&a,&b);
t=a,r=b;
scanf("%d",&n);
while((a+1)&&(b+1)&&i<=n)
{
scanf("%d %d %d %d",&c,&d,&e,&f);
if((c+e)==d)
{
a--;
}
if((c+e)==f)
{
b--;
}
if(a<0)
{
if(b<0)
{
a=0;
b=0;
}
}
}
m=a<0?'A':'B';
q=a<0?(r-b):(t-a);
printf("%c\n",m);
printf("%d\n",q);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,j,c,d,a[99999]={0},flag=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&c);
for(j=0;j<c;j++)
{
scanf("%d",&d);
if(c!=1)
{
a[d]=1;
}
}
}
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&c);
if(a[c]==0)
{
if(i!=0)
{
printf(" %05d",c);
}
else{
printf("%05d",c);
}
flag=1;
a[c]=1;
}
}
if(flag==0)
{
printf("No one is handsome");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int a=0,b=0,c=0,d=0,e,f,n,i=1,t,r,q;
char s[10000];
gets(s);
e=strlen(s);
for(i=0;i<e;i++)
{
switch(s[i])
{
case 'g':
case 'G':
a++;
break;
case 'p':
case 'P':
b++;
break;
case 'l':
case 'L':
c++;
break;
case 't':
case 'T':
d++;
break;
default:
break;
}
}
while(a||b||c||d)
{
if( a) { printf("G"); a--; }
if( b ) { printf("P"); b--; }
if( c ) { printf("L"); c--; }
if( d ) { printf("T"); d--; }
}
return 0;
}
一個整數“犯二的程度”定義爲該數字中包含2的個數與其位數的比值。如果這個數是負數,則程度增加0.5倍;如果還是個偶數,則再增加1倍。例如數字
-13142223336
是個11位數,其中有3個2,並且是負數,也是偶數,則它的犯二程度計算爲:3/11×1.5×2×100%3/11\times 1.5\times 2\times 100\%3/11×1.5×2×100%,約爲81.82%。本題就請你計算一個給定整數到底有多二。
輸入格式:
輸入第一行給出一個不超過50位的整數N
。
輸出格式:
在一行中輸出N
犯二的程度,保留小數點後兩位。
#include <stdio.h>
#include <stdlib.h>
int main()
{
double b=1;
long long a,c;
int e=0,d=0;
scanf("%lld",&a);
if(a<0)
{
b*=1.5;
a=-a;
}
c=a;
if(a%2==0)
{
b*=2;
}
while(c>0)
{
if(c%10==2)
{
d++;
}
c/=10;
e++;
}
b*=(double)d/e;
printf("%.2f%%\n",b*100);
return 0;
}
#include<stdio.h>
int main()
{
int G[105][105]={0},root[105],sw;
int a_root,b_root,a,b,c,n,m,k,i;
scanf("%d%d%d",&n,&m,&k);
for(i=0;i<105;i++)
root[i]=i;
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
G[a][b]=c;
G[b][a]=c;
if(c == 1)
{
i=a;
while(root[i]!=i)
i=root[i];
a_root=i;
i=b;
while(root[i]!=i)
i=root[i];
b_root=i;
if(a_root!=b_root)
root[b_root]=a_root;
}
}
while(k--)
{
scanf("%d%d",&a,&b);
i=a;
while(root[i]!=i)
i=root[i];
a_root=i;
i=b;
while(root[i]!=i)
i=root[i];
b_root=i;
if(G[a][b]==1)
{
printf("No problem\n");//一開始我這裏還加了判斷的,但是直接這樣就行了,否則過不了
}
else if(G[a][b]==0)
{
printf("OK\n");//介裏也是
}
else
{
if(a_root==b_root)//就這個地方要判斷,我語文水平真的不好。。。
printf("OK but...\n");
else
printf("No way\n");
}
}
}