আমি মনে করি আমার কোড ঠিক আছে, কিন্ত কাজ করে না। ‌__** লিখলে প্রিন্ট হয় <i>_<b>*

Problem
Code

asked 06 Feb, 11:38

pollob1563's gravatar image

pollob1563
27312

edited 07 Feb, 04:17

কোডের লিংক ভুল। এই কোডটি অন্য এক সমস্যার।

(06 Feb, 12:20) Mosharraf Hosain ♦

ঠিক করেছি ।

(06 Feb, 13:06) pollob1563

str.erase() বাদ দিলেই হয়।

bool uscore = true, star = true;
for (int i = 0; i < str.size(); i++) {
    if (str[i] == '_' and uscore) {
        cout << "<i>";
        uscore = false;
    } else if (str[i] == '_' and not uscore) {
        cout << "</i>";
        uscore = true;
    } else if (str[i] == '*' and star) {
        cout << "<b>";
        star = false;
    } else if (str[i] == '*' and not star) {
        cout << "</b>";
        star = true;
    } else cout << str[i];
}
cout << endl;
permanent link

answered 08 Feb, 17:33

Mosharraf%20Hosain's gravatar image

Mosharraf Hosain ♦
1.0k18

এই কোডটিতে সমস্যা কোথায়?

#include <bits/stdc++.h>
using namespace std;
#define str string
#define nl endl
#define nw cout<<endl
#define pb push_back
#define spc " "
#define tc(t) while(t--)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
typedef long long int lld;
int italic(str& a,int i,int n){
    for(;a[i]!='_'&&i<n;i++) cout<<a[i];
    if(i!=n) cout<<"</i>";
    return i;
}
int bold(str& a,int i,int n){
    for(;a[i]!='*'&&i<n;i++) cout<<a[i];
    if(i!=n) cout<<"</b>";
    return i;
}
int main()
{
    FAST;
    int i;
    str a;
    while(getline(cin,a)){
        for(i = 0; i < a.size(); i++){
            if(a[i]=='_'){
                cout<<"<i>";
                i++;
                i = italic(a,i,a.size());
            }
            else if(a[i]=='*'){
                cout<<"<b>";
                i++;
                i = bold(a,i,a.size());
            }
            else cout<<a[i];
        }
        nw;
    }
    return 0;
}
permanent link

answered 24 May, 08:52

pollob1563's gravatar image

pollob1563
27312

edited 24 May, 08:53

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×61
×15

question asked: 06 Feb, 11:38

question was seen: 353 times

last updated: 24 May, 08:53