- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
textField=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 200, 40)];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
textField.placeholder=@"请输入少于十的数字";
textField.keyboardType=UIKeyboardTypeNumberPad;
textField.delegate=self;
button =[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(240, 0, 80, 40);
[button setTitle:@"确定" forState:UIControlStateNormal];
[self.view addSubview:textField];
[self.view addSubview:button];
[textField release];
[button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
v=[[UIView alloc]initWithFrame:CGRectMake(0, 60, 320, 420)];
m_timer =[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(buttonClick) userInfo:nil repeats:YES];
}
-(void)buttonClick
{
int m=self.view.frame.size.width/[textField.text intValue];
for (UIView *v1 in v.subviews) {
[v1 removeFromSuperview];
}
n=[textField.text intValue];
NSLog(@"m---%d",m);
for (int i=0; i<[textField.text intValue]; i++) {
for (int j=0; j<[textField.text intValue]; j++) {
buttonImage=[UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonImage.backgroundColor=[UIColor grayColor];
buttonImage.frame=CGRectMake(m *i,j*100, m, 100);
buttonImage.tag=500*i+10*j;
[self setImage:buttonImage];
[v addSubview:buttonImage];
[self.view addSubview:v];
}
}
// [self setImage:buttonImage];
// m_timer =[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(setImage:) userInfo:nil repeats:YES];
}
-(void)setImage:(UIButton *)sender
{
int k = arc4random() % 8 ;
NSLog(@"n---%d",k);
// UIButton *button2=(UIButton *)[self.view viewWithTag:sender];
NSLog(@"sender----%@",sender);
// [sender setImage:[NSString stringWithFormat:@"cell%d.png",n] forState:UIControlStateNormal];
[sender setImage:[UIImage imageNamed:[NSString stringWithFormat:@"cell%d.png",k]] forState:UIControlStateNormal];
NSLog(@"rrrr");
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[textField resignFirstResponder];
}
// int arr1[] = {1,2,2,2,4,4,4,4,4,0,0,0,4,4,4,4};
void getMaxValue(int array[], int length){
int tempArray[10] = {};
int index = 0;
for (int i = 0; i < length; i++) {
if (i > 0) {
if (array[i] == array[i - 1]) {
//NSLog(@"i %d, %d", array[i], tempArray[index]%10);
tempArray[index] = array[i] * 10 + tempArray[index] % 10 + 1;
//NSLog(@"xx:%d", tempArray[index]);
}else {
index++;
tempArray[index] = array[i] * 10 + 1;
//NSLog(@"else ~ %d", tempArray[index]);
}
}else {
tempArray[i] = array[i] * 10 + 1;
//NSLog(@"else %d", tempArray[i]);
}
}
int temp;
//排序
for (int i = 0; i < sizeof(tempArray)/sizeof(int) - 1; i++) {
for (int j = 0; j < sizeof(tempArray)/sizeof(int) - i - 1; j++) {
if ((tempArray[j] < tempArray[j + 1]) && (tempArray[j] % 10 < tempArray[j + 1] % 10)) {
temp = tempArray[j + 1];
tempArray[j + 1] = tempArray[j];
tempArray[j] = temp;
}
}
}
//输出最大 v1
for(int i = 0; i < (tempArray[0] % 10); i++) {
printf("%d", tempArray[0] / 10);
}
printf("\n");
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
int arr1[] = {1,2,2,2,4,4,4,4,4,0,0,0,4,4,4,4};
int arr2[] = {1,3,3,3,4,4,4,4,4,0,0,0,0,0,0,0,5,5,5,5};
int arr3[] = {1,3,3,3,5,5,5,5,5,4,4,4,4,4,0,0,0,0,0,0,4,4,4,4};
getMaxValue(arr1, sizeof(arr1)/sizeof(int));
getMaxValue(arr2, sizeof(arr2)/sizeof(int));
getMaxValue(arr3, sizeof(arr3)/sizeof(int));
}
return 0;
}