QPython+SL4A:
import android
import time
import sys, select, os #for loop exit
#Initiate android-module
droid = android.Android()
#notify me
droid.makeToast("fetching GPS data")
print("start gps-sensor...")
droid.startLocating()
while True:
#exit loop hook
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
line = input()
print("exit endless loop...")
break
#wait for location-event
event = droid.eventWaitFor('location',10000).result
if event['name'] == "location":
try:
#try to get gps location data
timestamp = repr(event['data']['gps']['time'])
longitude = repr(event['data']['gps']['longitude'])
latitude = repr(event['data']['gps']['latitude'])
altitude = repr(event['data']['gps']['altitude'])
speed = repr(event['data']['gps']['speed'])
accuracy = repr(event['data']['gps']['accuracy'])
loctype = "gps"
except KeyError:
#if no gps data, get the network location instead (inaccurate)
timestamp = repr(event['data']['network']['time'])
longitude = repr(event['data']['network']['longitude'])
latitude = repr(event['data']['network']['latitude'])
altitude = repr(event['data']['network']['altitude'])
speed = repr(event['data']['network']['speed'])
accuracy = repr(event['data']['network']['accuracy'])
loctype = "net"
data = loctype + ";" + timestamp + ";" + longitude + ";" + latitude + ";" + altitude + ";" + speed + ";" + accuracy
print(data) #logging
time.sleep(5) #wait for 5 seconds
print("stop gps-sensor...")
droid.stopLocating()
Відповідь:
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void SetArray(int *A,int N){
for(int i = 0; i < N; i++){
A[i] = rand() % 10 + 1;
}
}
void PrintArray(int *A,int N){
for(int i = 0;i < N; i++){
cout << A[i] << " ";
}
}
void expression(int *A,int N,int k,int l){
for(int i = k; k < l; k++ , l--){
swap(A[k], A[l]);
}
}
int main(){
srand(time(NULL));
setlocale(LC_ALL , "Ukrainian");
int N,k,l;
cout << "Введiть розмiр масиву: ";
cin >> N;
int *A = new int[N];
SetArray(A,N);
PrintArray(A,N);
cout << "\nВведiть k: ";
cin >> k;
cout << "Введiть l: ";
cin >> l;
expression(A,N,k,l);
PrintArray(A,N);
delete[] A;
return 0;
}