For Loops Challenge
given below code is for pforloop spoj or For Loops Challenge spoj.
only one thing u have to consider number are consecutive .
#include <stdio.h> #include <algorithm> using namespace std; int a[100000]; int main() { int n,i=0,j,end,count=0; while(scanf("%d",&n)!=EOF) { a[i++]=n; } sort(a,a+i); for(j=1;j<=i;j++) { if(a[j]-a[j-1]==1){ count++; } else { end=a[j-1]; printf("for (int i = %ld; i <= %ld; i++) cout << i << \" \";\n",end-count,end); count=0; } } return 0; }
No comments:
Post a Comment
Your comment is valuable to us