zoukankan      html  css  js  c++  java
  • 练习题1

    //
    //  1.整数123456789,如何将这个整数的每一位数,从末位开始依次放入一个数组中,并将他们遍历出来
    //  2.如何将字符串@“abc123.xyz789”倒置
    //  3.将2013年05月05日转换成2013-05-05
    
    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            NSLog(@"第一题");
            NSInteger num=123456789;
            //NSNumber *newnum=@(num);
            NSString *strnum=[[NSString alloc]initWithFormat:@"%ld",num];
            NSMutableArray *arr=[NSMutableArray array];
            for (int i=8; i>=0; i--) {
                NSRange range;
                range.length=1;
                range.location=i;
                NSString *str=[NSString alloc];
                str=[strnum substringWithRange:range];
                [arr addObject:str];
            }
            for (id str1 in arr) {
                NSLog(@"%@",str1);
            }
            NSLog(@"第二题");
            NSString *string=@"abc123.xyz789";
            NSMutableString *newString=[[NSMutableString alloc]initWithCapacity:string.length];
            for (long i=string.length-1; i>=0; i--) {
                [newString appendFormat:@"%c",[string characterAtIndex:i]];
            }
            NSLog(@"%@",newString);
            NSLog(@"第三题");
            NSString *date=@"2013年05月05日";
            NSMutableString *Date=[NSMutableString stringWithString:date];
            NSRange rangeDate;
            int i=4;
            while (i<9) {
                rangeDate.length=1;
                rangeDate.location=i;
                [Date replaceCharactersInRange:rangeDate withString:@"-"];
                i+=3;
            }
            NSString *newdate=[Date substringToIndex:i];
            NSLog(@"%@",newdate);
        }
        return 0;
    }
  • 相关阅读:
    leetcode 1. Two Sum
    leetcode 168. Excel Sheet Column Title
    [LeetCode] Water and Jug Problem 水罐问题
    leetcode 80 Remove Duplicates from Sorted Array II
    leetcode 239. Sliding Window Maximum
    文件处理
    python网络编程 之 twisted
    ICMP & ping & traceroute
    Java String 转整形
    Java 字符数字得到整数
  • 原文地址:https://www.cnblogs.com/haitong-0311/p/5120864.html
Copyright © 2011-2022 走看看