problem link - click here
please read the statement carefully then you must get a way to solve it. you can use multiple if else statements to solve this problem or can use switch to solve. there will be given a string and you have to create a maze. the conditions are given so follow that. remember only A-Z, *(asterikh), digits (0 to 9) will be used as input. so think about these and forget handling the others.
an accepted code is as follows:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
int count=0;
for(int i=0;i<str.length();i++)
{
switch(str[i])
{
case 'b':
while(count--)
{
cout<<" ";
}
count = 0;
break;
case '1':
count = count+1;
break;
case '2':
count = count+2;
break;
case '3':
count = count+3;
break;
case '4':
count = count+4;
break;
case '5':
count = count+5;
break;
case '6':
count = count+6;
break;
case '7':
count= count+7;
break;
case '8':
count = count+8;
break;
case '9':
count = count+9;
break;
case '!':
cout<<endl;
break;
default:
while(count--)
{
cout<<str[i];
}
count = 0;
}
}
cout<<endl;
}
return 0;
}
please read the statement carefully then you must get a way to solve it. you can use multiple if else statements to solve this problem or can use switch to solve. there will be given a string and you have to create a maze. the conditions are given so follow that. remember only A-Z, *(asterikh), digits (0 to 9) will be used as input. so think about these and forget handling the others.
an accepted code is as follows:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
int count=0;
for(int i=0;i<str.length();i++)
{
switch(str[i])
{
case 'b':
while(count--)
{
cout<<" ";
}
count = 0;
break;
case '1':
count = count+1;
break;
case '2':
count = count+2;
break;
case '3':
count = count+3;
break;
case '4':
count = count+4;
break;
case '5':
count = count+5;
break;
case '6':
count = count+6;
break;
case '7':
count= count+7;
break;
case '8':
count = count+8;
break;
case '9':
count = count+9;
break;
case '!':
cout<<endl;
break;
default:
while(count--)
{
cout<<str[i];
}
count = 0;
}
}
cout<<endl;
}
return 0;
}
No comments:
Post a Comment