I got the x and y by a UITapGestureRecognizer set on the screen, after having obtained the location I find the object touched, so I put the conditions, but does not work. Maybe I put the wrong conditions in objective C? Xcode gives no errors but the function does not work.
-(void)tappedMapOniPad:(int)x andy:(int)y{
NSLog(#"the x is: %d", x);
//the x is: 302
NSLog(#"the y is: %d", y);
//the y is: 37
if((121<x<=181) && (8<y<=51)){ //the error is here
self.stand = 431;
}else if ((181<x<=257) && (8<y<=51)){
self.stand=430;
}else if ((257<x<=330) && (8<y<=51)){
self.stand = 429;
}
NSLog(#"The stand is %d", self.stand);
//The stand is 431
}
How can I do?
121<x<=181
let's assume x := 10 121<10<=181 -> false<=181 -> 0<=181 -> true
you have to do it step by step.
((121 < x) && (x <=181))
let's assume x := 10 ((121 < 10) && (10 <=181)) ->false && true ->false
Replace
if((121<x<=181) && (8<y<=51))
by
if((121 < x && x <= 181) && (8 < y && y <= 51))
(121<x<=181) kind of expression is invalid in Obj-c.
Use, (x>121 && x<=181)
Your full code will be like :
if((x>121 && x<=181) && (y>8 && y<=51)){ //the error is here
self.stand = 431;
}
else if ((x>181 && x<=257) && (y>8 && y<=51)){
self.stand=430;
}
else if ((x> 255 && x<=330) && (y>8 && y<=51)){
self.stand = 429;
}
Or you can optimize it as:
if(y>8 && y<=51){
if (x> 257 && x<=330) {
self.stand = 429;
}
else if(x>181){
self.stand=430;
}
else if(x>121){
self.stand = 431;
}
}
Missing &&
Try
if((121<x&&x <=181)&&(8<y&&y <=51))
Hope it helps
Related
https://codeforces.com/problemset/problem/118/A
my code:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string str;
cin >> str;
for(int i=0; i<sizeof(str); i++)
{
if(str[i] >= 'A' && str[i] <= 'Z')
str[i]+=32;
{
if(str[i] >= 'a' && str[i] <= 'z' && str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && str[i] != 'o' && str[i] != 'u' && str[i] != 'A' && str[i] != 'E' && str[i] != 'I' && str[i] != 'O' && str[i] != 'U')
cout << "." << str[i];
}
}
return 0;
}
Where is the problem in this code because it gives wrong when I submit?
I am not seeing any problem, could anyone help me to detect?
In the question they have included 'y' as a vowel too. I changed some other stuff too (like, use i<str.size() not i<sizeof(str) ), try the following code it will get accepted :
int main()
{
string str;
cin >> str;
for(int i=0; i<str.size(); i++)
{
char temp;
temp = str[i];
if(temp >= 'A' && temp <= 'Z')
temp = tolower(temp);
if(temp != 'a' && temp != 'e' && temp != 'i' && temp != 'o' && temp != 'u' && temp != 'y')
cout << "." << temp;
}
return 0;
}
I want to test the following property in Dafny: a^2<=b^2*c^2 implies a<=b*c. It automatically checks this for (positive) integer numbers:
lemma powersVSsquares_integers(a:int, b:int, c:int)
requires a>=0 && b>=0 && c>= 0
ensures (a*a <= b*b*c*c) ==> (a<=b*c)
{}
Now, I want to test this for real numbers, so I try:
lemma powersVSsquares_reals(a:real, b:real, c:real)
requires a>=0.0 && b>=0.0 && c>=0.0
ensures (a*a <= b*b*c*c) ==> (a<=b*c)
{}
But Dafny cannot prove this. Thus, I start with the case where a>=1.0 & b>=1.0 & c>=1.0:
lemma powersVSsquares_reals1(a:real, b:real, c:real)
requires (a>=1.0 && b>=1.0 && c>=1.0)
ensures (a*a <= b*b*c*c) ==> (a<=b*c)
{
assert a <= (b*b*c*c)/a;
}
But not even assert a <= (b*b*c*c)/a; can be proven. So I have no idea on how to deal with this prove.
Can anyone provide lemma powersVSsquares_reals proven in Dafny? Can this be done without defining a symbolic square root function?
I think you will need some axioms of the reals that are not readily available in Dafny.
lemma increase(a: real, b: real, x: real)
requires x > 0.0
requires a > b
ensures a * x > b * x
{
}
lemma zero(a: real)
requires a*a == 0.0
ensures a == 0.0
{
if a != 0.0 {
if a > 0.0 {
increase(a, 0.0, a);
assert false;
} else if a < 0.0 {
increase(-a, 0.0, -a);
assert false;
}
}
}
Then you can use these axioms to do a regular proof. Here I choose the style of a proof by contradiction
lemma powersVSsquares_reals(a:real, b:real, c:real)
requires a>=0.0 && b>=0.0 && c>=0.0
ensures (a*a <= (b*b)*(c*c)) ==> (a<=b*c)
{
if a*a <= (b*b)*(c*c) {
if a == 0.0 {
return;
}
if b == 0.0 || c == 0.0 {
zero(a);
return;
}
assert a*a <= (b*c)*(b*c);
if a > (b*c) {
assert b * c > 0.0;
increase(a, b*c, b*c);
assert a * (b*c) > (b * c) * (b*c);
assert a > 0.0;
increase(a, b*c, a);
assert a * a > (b * c) * a;
assert a * a > (b * c) * (b*c);
assert false;
}
assert a<=b*c;
}
}
I want to calculate the total duration a gif plays. It can be either duration of a gif or frame count of the gif. Have tried using FLAnimatedImage, SDWebImage and YYImage but can't really attain what I am looking for. The gif is loaded from remote url and then I want to calculate the duration it plays.
This is the function that returns the total duration in GIF time units (1 unit = 10 msec).
data is a pointer to GIF data, size is its size.
long Duration(uint8_t *data, long size) {
long desc, time = 0;
uint8_t *buff;
if ((size > 13) && data && (data[0] == 71) && (data[1] == 73)
&& (data[2] == 70) && (data[3] == 56) && (data[5] == 97)
&& ((data[4] == 55) || (data[4] == 57))) {
buff = data + 13 + ((data[10] & 0x80)? 6 << (data[10] & 7) : 0);
if ((size -= buff - data) > 0)
while ((desc = *buff++) != 0x3B) {
size--;
if (desc == 0x2C) {
desc = 9 + ((buff[8] & 0x80)? 6 << (buff[8] & 7) : 0);
buff += desc;
if ((size -= desc) <= 0)
break;
}
else if ((desc == 0x21) && (*buff == 0xF9))
time += *(uint16_t*)(buff + 3);
buff++;
if (--size <= 0)
break;
do {
buff += (desc = 1 + *buff);
if ((size -= desc) <= 0)
return time;
} while (desc > 1);
}
}
return time;
}
This function parses GIF images by hand, extracting frame delay information and summing it.
I have an if statement and the statement is only being run on the fist third of the condition (before the fist 'or' (||).
if (((day == 1) && (period == 1)) || ((day == 3) && (period == 3)) || ((day = 5) && (period == 1)))
{
NSLog(#"Return Line 1");
}
The condition is only met when day = 1 and period = 1. Could someone help me get the other arrangements working in the condition. Thank you in advance.
if (((day == 1) && (period == 1)) || ((day == 3) && (period == 3)) || ((day == 5) && (period == 1)))
{
NSLog(#"Return Line 1");
}
In your code there is only one = instead of ==
The error in your code is ((day = 5) && (period == 1))
Me and a group of friends are creating an iPhone app for a project in our technology class. Our app is going to be used for navigation to different high school sporting event locations in our area. We are currently using a PickerView to control all the combinations of school and sport. The picker has two components, one for schools and one for sports. We already have the MapView set up as well.
We are wondering how we can place the pins for all the different school/sport combinations using the outputs from the Picker View. As you can see in the code below, we currently have a ton of if/then statements to receive the outputs from the PickerView, but eventually want to make that less bulky as well.
Here is the code for the picker outputs:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
int x = [pickerView selectedRowInComponent:0]; NSLog(#"Row 1: %i", x);
int y = [pickerView selectedRowInComponent:1]; NSLog(#"Row 2: %i", y);
//Blue Ridge
if (x == 0 && y == 0)
{NSLog(#"Blue Ridge Basketball");}
else if (x == 0 && y == 1)
{NSLog(#"Blue Ridge Basketball");}
else if (x == 0 && y == 2)
{NSLog(#"Blue Ridge Cross Country");}
else if (x == 0 && y == 3)
{NSLog(#"Blue Ridge Football");}
else if (x == 0 && y == 4)
{NSLog(#"Blue Ridge Golf");}
else if (x == 0 && y == 5)
{NSLog(#"Blue Ridge Soccer");}
else if (x == 0 && y == 6)
{NSLog(#"Blue Ridge Softball");}
else if (x == 0 && y == 7)
{NSLog(#"Blue Ridge Track");}
else if (x == 0 && y == 8)
{NSLog(#"Blue Ridge Volleyball");}
else if (x == 0 && y == 9)
{NSLog(#"Blue Ridge Wrestling");}
//DeeMack
else if (x == 1 && y == 0)
{NSLog(#"DeeMack Baseball");}
else if (x == 1 && y == 1)
{NSLog(#"DeeMack Basketball");}
else if (x == 1 && y == 2)
{NSLog(#"DeeMack Cross Country");}
else if (x == 1 && y == 3)
{NSLog(#"DeeMack Football");}
else if (x == 1 && y == 4)
{NSLog(#"DeeMack Golf");}
else if (x == 1 && y == 5)
{NSLog(#"DeeMack Soccer");}
else if (x == 1 && y == 6)
{NSLog(#"DeeMack Softball");}
else if (x == 1 && y == 7)
{NSLog(#"DeeMack Track");}
else if (x == 1 && y == 8)
{NSLog(#"DeeMack Volleyball");}
else if (x == 1 && y == 9)
{NSLog(#"DeeMack Wrestling");}
}
...etc, This format continues for 11 more schools.
Any ideas as to how we can use these outputs to drop the pins on the map, or ideas to make this code shorter would be greatly appreciated. Also it is important to note that we are all very new to coding, so the simpler the better. Thanks!
To make the code shorter, all you need to do is maintain 2 arrays, one containing the high school names and the other containing the sports.
So create 2 NSArrays as properties of your controller
#property (strong, nonatomic) NSArray *highSchools;
#property (strong, nonatomic) NSArray *sports;
and then in the viewDidLoad method, do this :
self.highSchools = [NSArray arrayWithObjects:#"Blue Ridge", #"DeeMack," nil];
self.sports = [NSArray arrayWithObjects:#"Baseball", #"BasketBall", #"Cross Country", nil];
So now your picker delegate method will reduce to this ::
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
int x = [pickerView selectedRowInComponent:0]; NSLog(#"Row 1: %i", x);
int y = [pickerView selectedRowInComponent:1]; NSLog(#"Row 2: %i", y);
NSLog(#"%# %#", [self.highSchools objectAtIndex:x], [self.sports objectAtIndex:y]);
}
Now, for placing the pins, its not clear from the question, exactly how or where you want to place them and what the pins represent. It seems like you want to drop a single pin on the map depending on a school/sport combination at the location of the selected school. Is that right?