PCDVD數位科技討論區

PCDVD數位科技討論區 (https://www.pcdvd.com.tw/index.php)
-   疑難雜症區 (https://www.pcdvd.com.tw/forumdisplay.php?f=34)
-   -   如何做出牌3個數字的C程式 (https://www.pcdvd.com.tw/showthread.php?t=849574)

huwiam99 2009-04-24 09:51 AM

如何做出牌3個數字的C程式
 
我想把中間有空白的地方加入3個數字做排序,從大到小(紅色的部份)

#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <stdlib.h>

#define infile "input2.txt"
#define Max_Length 10

int v[Max_Length];
int data_length;

void initialize();
void read_file();
void perm(int i, int n);
void swap(int *a, int *b);

int main()
{
initialize();
read_file();
perm(0, data_length-1);

return 0;
}

void perm(int i, int n)
{
int j;

if(i==n)
{


}
else
{
for(j=i; j<=n; j++)
{
swap(&v[i], &v[j]);


}
}
}

void swap(int *a, int *b)
{
int temp;

temp = *a;
*a = *b;
*b = temp;
}

void initialize()
{
int i;

for(i=0; i<Max_Length; i++)
v[i] = 0;
}

void read_file()
{
int i;

ifstream fin(infile, ios::in);

i=0;
while (fin >> v[i])
i++;
data_length = i;

fin.close();
}


所有的時間均為GMT +8。 現在的時間是06:09 AM.

vBulletin Version 3.0.1
powered_by_vbulletin 2025。