can anyone write shorter solotion than mine ?
Posted by
Saber 6 Feb 2003 16:12
here is mine :
var
n,i : longint;
begin
readln (n);
for i := 1 to n do
write (i,' ');
end.
Many people knows that, don't be so......
Posted by
Lucky 6 Feb 2003 16:30
DOnt be selfish!
U can use integer instead of longint and also write for loop, in just
one line!!!
anyhow...
solotion has no meaning!
you should say: solution...
Your Friend
Aidin_n7
Re: can anyone write shorter solotion than mine ?
program tm_1082;
var
N: 0..1000;
begin
Readln(N);
while boolean(n) do
begin
write(-N,' ');
Dec(N)
end;
end.
Re: can anyone write shorter solotion than mine ?
Posted by
yuhc 10 Jun 2009 18:36
var n,i :integer;
begin
readln(n);
for i := 1 to n do write(i,' ');
end.
Re: can anyone write shorter solotion than mine ?
#include <stdio.h>
void main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++) printf("%d ",i); }
Re: can anyone write shorter solotion than mine ?
NOT shorter BUT better
i can give you a hint...
ok
we start with 1
if you input 1->ok
if you input 1->ok
if you input 3->ok
if you input 7(3*2+1)->ok
if you input 19(7*2+3*2)->ok
if you input 52(19*2+7*2)->ok
...............................
have you got it....
if not stat with 1;
read n
a=1;
b=3;
n--;
write b
a=b;
b=a+b*2;
for 1->n
{
write b*2+a*2
}
:)
not shorter but better:D
Re: can anyone write shorter solotion than mine ?
#include<cstdio>
int main(){int n;scanf("%d",&n);for(;n;n--)printf("%d ",-n);}
Edited by author 16.09.2010 04:37
Re: can anyone write shorter solotion than mine ?
#include<stdio.h>
main(){int n;scanf("%d",&n);while(n*printf("%d ",-n--));}
Edited by author 23.10.2010 21:23
Edited by author 23.10.2010 22:24
Re: can anyone write shorter solotion than mine ?
Use <cstdio> =)
Re: can anyone write shorter solotion than mine ?
OMG!
Re: can anyone write shorter solotion than mine ?
#include<stdio.h>
main(){int n;scanf("%d",&n);while(n*printf("%d ",-n--));}
Concise, but, strictly speaking, is not guaranteed to work properly - as it is with all expressions of kind a[i] = i++. E.g., clang gives error - "unsequenced modification and access to 'n'". The problem here is that in C/C++ all side-effects of arguments to functions are computed *before* function call. To fix this, we need to introduce a sequence point (
https://en.wikipedia.org/wiki/Sequence_point) - e.g., comma:
#include<stdio.h>
main(){int n;scanf("%d",&n);while(n*printf("%d ",-n),--n);}
Edited by author 12.02.2016 12:31Re: can anyone write shorter solution than mine ?
print(*list(int(x)+1 for x in range(int(input()))))
can anyone shorter?
Edited by author 28.02.2016 00:45
Re: can anyone write shorter solution than mine ?
41 bytes (Python 2.7)
print ' '.join(map(str,range(int(input()))))
27 bytes (Python 3.6)
print(*range(int(input())))
Edited by author 17.03.2018 00:52