#include "stdafx.h"
#include "stdio.h"
#include "iostream"
#define N 1000
int tianji[N];
int king[N];
int x,tx, //赢得次数
y,ty, //输的次数
z,tz; //平的次数
//x,y,z 用来存放最终结果
void prt(int a[], int n);
void sort(int a[], int n)//有打到小排序
{
int x, y;
int temp;
for(x = 0; x < n; x++)
{
for(y = x+1; y < n; y++)
{
if(a[x] < a[y])
{
temp = a[x];
a[x] = a[y];
a[y] = temp;
}
}
}
}
void f(int tianji[], int king[], int n) // 把符合条件数字写入全局变量 x,y,z中
{
int i,j;
int temp;
int k;
sort(tianji, n);
printf("tianji ");
prt(tianji, n);
sort(king, n);
printf("king ");
prt(king , n);
for(i = 0; i < n; i++) // 循环比较
{
k = 0;
temp = i;//保存
i = 0;
for(j = temp ; j < n; j++,i++)
{
if(tianji[i] > king[j])
{
tx++;
}
else if(tianji[i] < king[j])
{
ty++;
}
else
{
tz++;
}
}
ty += temp;
if((tx-ty) > (x-y))
{
x = tx;
y = ty;
z = tz;
}
i = temp;//恢复
k++;
tx = 0;
ty = 0;
tz = 0;
}
}
void init(int a[], int n) //初始化数组
{
int i;
for(i = 0; i < n; i++)
{
a[i] = rand()%100;
}
}
void prt(int a[], int n) //打印数组
{
int i;
for(i = 0; i < n; i++)
{
printf("%4d",a[i]);
}
printf("\n");
}
int main()
{
int n;
n = 8;
init(tianji,n);
init(king, n);
printf("tianji ");
prt(tianji, n);
printf("king ");
prt(king , n);
puts("***********************************");
f(tianji, king ,n);
printf("\n");
printf("\n赢的次数x = %d",x);
printf("\n输的次数y = %d\n",y);
printf("平的次数z = %d\n",z);
}
#include "stdio.h"
#include "iostream"
#define N 1000
int tianji[N];
int king[N];
int x,tx, //赢得次数
y,ty, //输的次数
z,tz; //平的次数
//x,y,z 用来存放最终结果
void prt(int a[], int n);
void sort(int a[], int n)//有打到小排序
{
int x, y;
int temp;
for(x = 0; x < n; x++)
{
for(y = x+1; y < n; y++)
{
if(a[x] < a[y])
{
temp = a[x];
a[x] = a[y];
a[y] = temp;
}
}
}
}
void f(int tianji[], int king[], int n) // 把符合条件数字写入全局变量 x,y,z中
{
int i,j;
int temp;
int k;
sort(tianji, n);
printf("tianji ");
prt(tianji, n);
sort(king, n);
printf("king ");
prt(king , n);
for(i = 0; i < n; i++) // 循环比较
{
k = 0;
temp = i;//保存
i = 0;
for(j = temp ; j < n; j++,i++)
{
if(tianji[i] > king[j])
{
tx++;
}
else if(tianji[i] < king[j])
{
ty++;
}
else
{
tz++;
}
}
ty += temp;
if((tx-ty) > (x-y))
{
x = tx;
y = ty;
z = tz;
}
i = temp;//恢复
k++;
tx = 0;
ty = 0;
tz = 0;
}
}
void init(int a[], int n) //初始化数组
{
int i;
for(i = 0; i < n; i++)
{
a[i] = rand()%100;
}
}
void prt(int a[], int n) //打印数组
{
int i;
for(i = 0; i < n; i++)
{
printf("%4d",a[i]);
}
printf("\n");
}
int main()
{
int n;
n = 8;
init(tianji,n);
init(king, n);
printf("tianji ");
prt(tianji, n);
printf("king ");
prt(king , n);
puts("***********************************");
f(tianji, king ,n);
printf("\n");
printf("\n赢的次数x = %d",x);
printf("\n输的次数y = %d\n",y);
printf("平的次数z = %d\n",z);
}