first commit
This commit is contained in:
108
计算机组成原理实验代码/OPT.cpp
Normal file
108
计算机组成原理实验代码/OPT.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int number=0;
|
||||
int Pyblock=0;
|
||||
int opt(int a[])
|
||||
{
|
||||
int i, j, zero = 0, one = 0, two = 0, q = 0;
|
||||
int b[Pyblock];
|
||||
for (i = 0; i < Pyblock; i++)
|
||||
{
|
||||
b[i] =-1; //<2F><>Ϊ-1
|
||||
}
|
||||
for (i = 0; i < number; i++)
|
||||
{
|
||||
if (i < 3)
|
||||
{
|
||||
q++;
|
||||
for (j = 0; j < Pyblock; j++)
|
||||
{
|
||||
if (b[j] == -1)
|
||||
{
|
||||
b[j] = a[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (b[0] != a[i])
|
||||
{
|
||||
if (b[1] != a[i])
|
||||
{
|
||||
if(b[2] != a[i]){
|
||||
q++;
|
||||
for (int t = i + 1; t < number; t++)
|
||||
{
|
||||
if (b[0] == a[t])
|
||||
zero = 1;
|
||||
else if (b[1] == a[t])
|
||||
one = 1;
|
||||
else if (b[2] == a[t])
|
||||
two = 1;
|
||||
if (zero == 1 && one == 1 && two == 0)
|
||||
{
|
||||
b[2] = a[i];
|
||||
break;
|
||||
}
|
||||
else if (zero == 1 && one == 0 && two == 1)
|
||||
{
|
||||
b[1] = a[i];
|
||||
break;
|
||||
}
|
||||
else if (zero == 0 && one == 1 && two == 1)
|
||||
{
|
||||
b[0] = a[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int f = 0; f < Pyblock; f++)
|
||||
{
|
||||
printf("%d\t", b[f]);
|
||||
}
|
||||
printf("\n");
|
||||
zero = 0;
|
||||
one = 0;
|
||||
two = 0;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int o;
|
||||
|
||||
while(1)
|
||||
{
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD><EFBFBD>:\n");
|
||||
scanf("%d",&Pyblock);
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><EFBFBD><EFBFBD>:\n");
|
||||
scanf("%d",&number);
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
int a[number];
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
cin>>a[i];
|
||||
}
|
||||
printf("optҳ<EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD>㷨<EFBFBD><EFBFBD>\n");
|
||||
o = opt(a);
|
||||
printf("ȱҳ%d<>Σ<EFBFBD><CEA3>û<EFBFBD>%d<><64>, ȱҳ<C8B1><D2B3>:%.2f%% .\n\n\n", o, o - Pyblock,((double)o/number)*100);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//4 3 2 1 4 3 5 4 3 2 1 5
|
||||
|
Reference in New Issue
Block a user