//
// main.m
// 第七次作业
//
// Created by YIem on 15/11/18.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import <Foundation/Foundation.h>

import "MyACEn.h"

int main(int argc, const char * argv[]) {

// .1输入10个整数,将其中最小的数与第一个数对换,把最大的数和最后一个数对换,指针实现

if 0

int a[10] = {0};
for (int i = 0; i < 10; i++) {
    *(a + i) = arc4random() % 11;
    printf("%d ", *(a + i));
}
printf("\n");
exchageMaxAndMin(a, 10);
for (int i = 0; i < 10; i++) {
    printf("%d ", *(a + i));
    
}
printf("\n");

endif

if 0

// .2输入10个等长的字符串。用另一个函数对它们排序,然后输出10个已经排好的字符串。
char *strings[] = {"qq", "ww", "ee", "rr", "tt", "yy", "uu", "ii", "oo", "pp"};
for (int i = 0; i < 10; i++) {
    printf("%s ", strings[i]);
}
printf("\n");
sortString(strings, 10);
for (int i = 0; i < 10; i++) {
    printf("%s ", strings[i]);
}
printf("\n");

endif

/// 3.

char str[] = "a1b22c3d4f55";

deleteNumber(str);
printf("%s\n", str);



/// .4

float a = 0, b = 0, c = 0;
scanf("%f%f%f", &a, &b, &c);

exchanggeMaxAndMin(&a, &b, &c);
printf("%f %f %f\n", a, b, c);



return 0;

}



//
// MyACEn.h
// 第七次作业
//
// Created by YIem on 15/11/20.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import <Foundation/Foundation.h>

// .h

/// 1.交换
void exchageMaxAndMin(int *a, int count);
/// 2.排序
void sortString(char *s[], int count);
/// 3.
void deleteNumber(char *s);

/// 4.
void exchanggeMaxAndMin(float a, float b, float *c);



//
// MyACEn.m
// 第七次作业
//
// Created by YIem on 15/11/20.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import "MyACEn.h"

// .m

/// 1.交换
void exchageMaxAndMin(int *a, int count) {

int max = 0, min = 10;
int iMax = 0, iMin = 0;
for (int i = 0; i < count; i++) {
    // 最大值
    if (max < *(a + i)) {
        max = *(a + i);
        iMax = i;
    }
    if (min < *(a + i)) {
        min = *(a + i);
        iMin = i;
    }
    
}
// 最大值和最后一位交换
int tMax = *(a + iMax);
*(a + iMax) = *(a + count - 1);
*(a + count - 1) = tMax;
// 最小值
int xMin = *(a + iMin);
*(a + iMin) = *(a + 0);
*(a + 0)= xMin;

}
/// 2.排序
void sortString(char *s[], int count) {

for (int i = 0; i < count - 1; i++) {
    for (int j = 0; j < count - 1 - i; j++) {
        if (strcmp(*(s + j), *(s + j + 1)) > 0) {

// char temp[10] = "";
// strcpy(temp, *(s + j));
// strcpy((s + j), (s + j + 1));
// strcpy(*(s + j + 1), temp);

            
            
            char *temp = *(s + j);
            *(s + j) = *(s + j + 1);
            *(s + j + 1) = temp;
            
        }
    }
}

}

/// 3.
void deleteNumber(char *s) {

while (*s) {
    // 如果遇到数字 让数字之后一位开始 整体向前覆盖
    if (*s >= '0' && *s <= '9') {
        strcpy(s, s + 1);
    } else {
        // 如果不是数子 继续向后遍历
        s++;
    }
}

}

/// 4.
void exchanggeMaxAndMin(float a, float b, float *c) {

// 保存最大值最小值对应的地址
float *pMax = NULL, *pMin = NULL;
pMax = *a > *b ? a : b;
pMax = *pMax > *c ? pMax : c;

pMin = *a < *b ? a : b;
pMin = *pMin < *c ? pMin : c;
float temp = *pMax;
*pMax = *pMin;
*pMin = temp;

}