WA in DECSTR

#include
#include

                using namespace std;

                int main(){
                   std::ios_base::sync_with_stdio(false);
                vector <long int> v;
                int t1,x,t;
                cin>>t1;
                for(int i=0;i<t1;i++)
                {
                 cin>>x;
                 v.push_back(x);
                }


                for(int i=0;i<t1;i++)
                {

                        t=v.at(i)%25;


                 for(int j=t;j>=0;j--)
                 {
                    cout<<static_cast<char>('a'+j);
                 }


                for(int l=0;l< static_cast<int>(v.at(i)/25);l++)
                    cout<<"zyxwvutsrqponmlkjihgfedcba";



                 cout<<endl;



                }


                return 0;
                }

Iā€™m getting WA, any hopes?

the loop :
for(int j=t;j >=0;jā€“)

             {

                cout<< static_cast < char > ('a'+j);<Br>
             }<bR>
is causing the error.

This loop shouldnā€™t be printing ā€˜aā€™ when t==0 because we are supposed to print the minimum length string, so,

The Correction is:

if(t>0)

{

             for(int j=t;j>=0;j--)

             {

                cout<< static_cast < char > ('a'+j);

             }

}

It should work after this correction,

If still there is WA, let me know in the comments below, I will help you out.

Happy Coding

Cheers

Yup, that did the trick, thanksā€¦

1 Like

WHAT IS WRONG IN MY CODE?
#include
#include<string.h>
using namespace std;
int main()
{
int t,k,i,r,m;
string c=ā€œzyxwvutsrqponmlkjihgfedcbaā€;
cin>>t;
while(tā€“)
{
cin>>k;
if(k<=25)
{
for(i=25-k;i<26;i++)
cout<<c.at(i);
}
else
{
r=k/25;
m=k%25;
for(i=25-m;i<26;i++)
cout<<c.at(i);
while(rā€“)
cout<<c;
}
cout<<endl;
}
}