Sunday 27 March 2016

Solution of URI 2028 :: Sequence of Sequence


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int n, i, j, cnt=0;
    while(scanf("%d", &n) != EOF)
    {
        int num = 1;
        cnt++;
        num += ((n*(n + 1)) / 2);
        if(n == 0) printf("Caso %d: %d numero\n", cnt, num);
        else printf("Caso %d: %d numeros\n", cnt, num);
        printf("0");
        for(i=1; i<=n; i++)
        {
            for(j=1; j<=i; j++)
                printf(" %d", i);
        }
        printf("\n\n");
    }
    return 0;
}

10 comments:

  1. vai apnar num songkhay vul asce... tai error dekhacce..

    ReplyDelete
    Replies
    1. দুঃখিত।
      আমি কোন ভুল পাচ্ছি না।
      num সংখ্যা ঠিক আছে।
      আর এই solution সব টেস্ট কেস পাশ হইতে পারছে।
      ধন্যবাদ।

      Delete
  2. alsalam alykom
    when write num+=n*(n+1)/2 why don't we write num+=n
    thanks

    ReplyDelete
    Replies
    1. Suppose, for n = 3, their contain 7 number on the sequence.
      And we get this by using this law.
      Initially 'num' is equal 1.
      so, num+=n*(n+1)/2;
      => num = num + n*(n+1)/2;
      => num = 1 + 3*(3+1)/2;
      .'. num = 7

      Delete
    2. This comment has been removed by the author.

      Delete
    3. that's right I understand when write n=3 as the first input this output 7 number so when I write num=1 in first code not in looping and num+=n this is making num depend on the n=0,1,2 that's not written as first inputs

      Delete
  3. #include

    void main()
    {
    int n, i=1, count, j, k;
    while(scanf("%d",&n)!=EOF){
    count=1;
    for(j=1;j<=n;j++)count+=j;
    if(n==0)printf("Caso %d: 1 numero\n", i);
    else printf("Caso %d: %d numero\n", i, count);
    printf("0");
    for(j=0;j<=n;j++){
    for(k=0;k<j;k++){
    printf(" %d",j);
    }
    }printf("\n\n");
    i++;
    }
    }

    ReplyDelete
  4. #include

    void main()
    {
    int n, i=1, count, j, k;
    while(scanf("%d",&n)!=EOF){
    count=1;
    for(j=1;j<=n;j++)count+=j;
    if(n==0)printf("Caso %d: 1 numero\n", i);
    else printf("Caso %d: %d numero\n", i, count);
    printf("0");
    for(j=0;j<=n;j++){
    for(k=0;k<j;k++){
    printf(" %d",j);
    }
    }printf("\n\n");
    i++;
    }
    }



    Whats wrong in it sir?

    ReplyDelete
  5. ar IF ELSE er ki kono dorkar ase eikhane?

    ReplyDelete
  6. where is the problem ,,seen,,presentation error ,,can anyone say?///
    #include
    using namespace std;
    int main()
    {
    int n,i,j,k=0,l;
    while(scanf("%d",&n)!=EOF)
    {
    k++;
    i=0;

    if(n==0)
    {
    i=1;

    cout<<"Caso "<<k<<": "<<i<<" numero"<<endl;
    printf("%d\n\n",n);
    }
    else
    {
    i=1;
    for(j=1; j<=n; j++)
    {
    i+=j;
    }
    cout<<"Caso "<<k<<": "<<i<<" numeros"<<endl;
    for(j=0; j<=n; j++)
    {
    if(j==0)
    {
    cout<<j<<" ";
    }
    else
    {

    for(l=1; l<=j; l++)
    {
    cout<<j<<" ";
    }
    }

    }
    printf("\n\n");

    }


    }
    return 0;
    }

    ReplyDelete

Note: only a member of this blog may post a comment.