Sunday, December 17, 2017

UVa problem solution 12554 - A Special "Happy Birthday" Song!!!

problem link:

Discuss: this is also implementation problem.if you know string then you can simply do it with it. and you can also do it with structure.you can use while to count.and print multiple of 16.


try your self, before see the code




#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,cnt=0,flag=0,m;
    double d;
    string str[101];
    string check[]={"Happy","birthday","to","you","Happy","birthday","to","you","Happy","birthday","to","Rujia","Happy","birthday","to","you"};
    cin >>n;
    for(i=0;i<n;i++)
    {
        cin >>str[i];
    }
    d=n/16.0;
    m=ceil(d)*16;
    i=0,j=0;
    while(1)
    {
          if(i==n)
            i=0;
          if(j==16)
            j=0;
       cout <<str[i]<<':'<<' ';
       cout <<check[j]<<endl;
       i++;
       j++;
       cnt++;
       if(cnt==m)
        break;
    }

}

No comments:

Post a Comment