zoukankan      html  css  js  c++  java
  • 省市县用对象实现

    //

    //  main.m

    //  练习省市区用对象实现

    //

    //  Created by dllo on 15/11/3.

    //  Copyright (c) 2015 dllo. All rights reserved.

    //


    #import <Foundation/Foundation.h>

    #import "Operation.h"

    #import "City.h"

    #import "provice.h"


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

        @autoreleasepool {

            Operation *oper = [[Operation alloc] init];

            [oper operation];

            [oper info];

        }

        return 0;

    }

    //

    //  Operation.h

    //  练习省市区用对象实现

    //

    //  Created by dllo on 15/11/4.

    //  Copyright (c) 2015 dllo. All rights reserved.

    //


    #import "City.h"

    @class provice;

    @class City;

    @interface Operation : City

    @property (nonatomic, retain)NSMutableArray *proArr;

    @property (nonatomic, retain)NSArray *arr;

    - (id)init;

    - (void)operation;

    - (void)info;

    @end


    //

    //  Operation.m

    //  练习省市区用对象实现

    //

    //  Created by dllo on 15/11/4.

    //  Copyright (c) 2015 dllo. All rights reserved.

    //


    #import "Operation.h"

    @class provice;

    @class City;

    @implementation Operation

    - (id)init

    {

        NSString *filePath = @"/Users/dllo/Desktop/省市区/area.txt";

        NSString *str = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

       // NSMutableArray *arr = [NSMutableArray array];

        NSArray *arr  = [str componentsSeparatedByString:@" "];

        NSMutableArray *proArr = [NSMutableArray array];

        self = [super init];

        if (self) {

            [self setProArr:proArr];

            [self setArr:arr];

        }

        return self;

    }

    - (void)operation

    {

        for (NSString *temp in self.arr) {

            if (![temp hasPrefix:@" "]) {

                provice *pro = [[provice alloc]init];

                [pro setProName:temp];

                [self.proArr addObject:pro];

            } else if([temp hasPrefix:@"  "] && ![temp hasPrefix:@"   "]) {

                City *city = [[City alloc]init];

                [[[self.proArr lastObject] cityArr]addObject:city];

                [[[[self.proArr lastObject] cityArr]lastObject]setCityName:temp];

                

            } else {

                [[[[[self.proArr lastObject] cityArr ]lastObject] quArr]addObject:temp];

            }

        }

    }

    - (void)info

    {

        for (provice *pro in self.proArr) {

            NSLog(@"%@", [pro proName]);

            for (City *city in pro.cityArr) {

                NSLog(@"%@", [city cityName]);

                for (NSString *temp in city.quArr) {

                    NSLog(@"%@", temp);

                }

            }

        }

    }

    @end


    //

    //  City.h

    //  练习省市区用对象实现

    //

    //  Created by dllo on 15/11/4.

    //  Copyright (c) 2015 dllo. All rights reserved.

    //


    #import "provice.h"


    @interface City : provice


    @property (nonatomic, retain)NSMutableArray *quArr;

    @property (nonatomic, copy)NSString *cityName;

    - (id)init;

    @end


    //

    //  City.m

    //  练习省市区用对象实现

    //

    //  Created by dllo on 15/11/4.

    //  Copyright (c) 2015 dllo. All rights reserved.

    //


    #import "City.h"


    @implementation City

    - (id)init

    {

        NSMutableArray *quArr = [NSMutableArray array];

        NSString *cityName = [[NSString alloc]init];

        self = [super init];

        if (self) {

            [self setQuArr:quArr];

            [self setCityName:cityName];

        }

        return self;

    }

    @end


    //

    //  provice.h

    //  练习省市区用对象实现

    //

    //  Created by dllo on 15/11/4.

    //  Copyright (c) 2015 dllo. All rights reserved.

    //


    #import <Foundation/Foundation.h>


    @interface provice : NSObject

    @property (nonatomic, retain)NSMutableArray *cityArr;

    @property (nonatomic, copy)NSString *proName;

    - (id)init;

    @end


    //

    //  provice.m

    //  练习省市区用对象实现

    //

    //  Created by dllo on 15/11/4.

    //  Copyright (c) 2015 dllo. All rights reserved.

    //


    #import "provice.h"


    @implementation provice

    - (id)init

    {

        NSMutableArray *cityArr = [NSMutableArray array];

        NSString *proName = [[NSString alloc]init];

        self = [super init];

        if (self) {

            [self setProName:proName];

            [self setCityArr:cityArr];

            

        }

        return self;

    }

    @end



  • 相关阅读:
    ContextMenustrip 控件
    Toolstrip 工具栏控件
    Menustrip控件和ContextMenustrip控件
    TabControl 选项卡控件
    GroupBox 分组框控件
    Pnel控件
    【bzoj3427】Poi2013 Bytecomputer dp
    【bzoj3174】[Tjoi2013]拯救小矮人 贪心+dp
    【bzoj1334】[Baltic2008]Elect 背包dp
    【bzoj1369】[Baltic2003]Gem 树形dp
  • 原文地址:https://www.cnblogs.com/yuhaojishuboke/p/5043111.html
Copyright © 2011-2022 走看看