include
using namespace std;
main()
{
int a[10], n=5, c;
for(c=0;c {
cin >>a[c];
}
for(c=0;c {
if(a[c]!=42)
{
cout << a[c]<< '\n';
}
else
{
return 0;
}
};
return 0;
}
even if i made it to stop after reading 42 ... i'm unable to remove 'n' or the limit of for loop ... it needs an upper limit to be defined. for(c=0; ???;c++)
While Delshire's code does work and gets AC, it has one interesting quirk.
while(a <= 100)
It is given in the problem statement that the numbers "are integers of one or two digits" so this works fine. It would be more acceptable to see:
while(true)
or, since it is given that there is always a 42 in the input statement:
while(a != 42)
This last segment also removes the need for the extra break, giving the loop a single exit point.
#include <iostream>
using namespace std;
int main() {
int a = 0;
while(a != 42) {
cin >> a;
if(a != 42)
cout << a << endl;
}
}
Hello! Thanks for the quick reply, i brought another piece of code, a little more 'formal' i think:
#include <iostream>
using namespace std;
void displayOutput(int myArray[], int qOfNumbers);
int main()
{
int inputValues[100] = {};
for(int i = 0; inputValues[i] < 100; i++)
{
int holder;
cin >> holder;
inputValues[i] = holder;
if (inputValues[i] == 42){
displayOutput(inputValues, i);
break;
}
}
}
void displayOutput(int myArray[], int qOfNumbers)
{
for(int a = 0; a < qOfNumbers; a++)
{
cout << myArray[a] << "\n";
}
}
18 1
1 2
2 3
3 3
3 2
2 4
4 5
5 6
6 5
5 7
7 8
8 9
9 10
10 11
11 12
12 2
2 1
1 2
2 1
Odpowiedź brzmi NIE ??
#include <stdio.h>
int main()
{
int p, t, k;
long long x, y;
bool test = true;
scanf("%d %d", &t, &p);
long long int tab[t][2];
for(int i =0; i<t; i++)
{
scanf("%lld %lld", &x, &y);
tab[i][0]=x;
tab[i][1]=y;
if(test == true)
{
if(i == 0)
{
if(x != p)
{
test = false;
}
}
if(i != 0)
{
if(x != k)
{
test = false;
}
}
k=y;
}
}
if( y != p)
test = false;
if(test==true)
{
for(int i =0; i<t; i++)
{
for(int j=0; j<t; j++)
{
if(i!=j)
{
if((tab[i][0] == tab[j][0]) && (tab[i][1] == tab[j][1]))
{
test=false;
break;
}
}
}
if(test==false)
break;
}
}
if(test == true)
printf("TAK");
else
printf("NIE");
return 0;
}
Mam coś takiego. Nie wiem co może być jeszcze źle
Co do testu - odpowiedzią jest "TAK".
Co do programu - masz błędny algorytm.
Zastanów się nad czymś takim: Jeśli, którąś ulicą dojdzie się do danego skrzyżowania, to jakąś inną trzeba z niego wyjść. Czyż nie?
A może próbowałeś kiedyś rysować pewne figury "jednym pociągnięciem ołówka"? Które figury da się tak narysować?
A tak w ogóle, to przeczytaj cały ten wątek, bo znajdziesz tu dużą podpowiedź.