0% found this document useful (0 votes)
21 views2 pages

#Include #Include #Include Using Namespace Int

The C++ program takes two input strings, line1 and line2, and compares them. It searches line1 for the substring "aaaa" and outputs the location where it is found, erasing that substring from both lines. It counts the number of matches and mismatches between the two lines.

Uploaded by

Surabhi Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

#Include #Include #Include Using Namespace Int

The C++ program takes two input strings, line1 and line2, and compares them. It searches line1 for the substring "aaaa" and outputs the location where it is found, erasing that substring from both lines. It counts the number of matches and mismatches between the two lines.

Uploaded by

Surabhi Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

// string3.cpp: Inputs and compares lines of text.

#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main()
{
string line1, line2;
line1 = "aaaa bbbb cccc caaaa baaaab aaaa cccc";
line2 = line1;
int count = 0, decount = 0;
int location;
while (line1.find("aaaa") != -1)
{
location = line1.find("aaaa");
if (location == 0)
{
if (line1[location + 4] = ' ')
{ // True Alarm
cout << location + (count * 4)<< endl;
count = count + 1;
line1.erase(location,4);
line2.replace
}
else
{
count = count + 1;
line1.erase(location,4);
decount = decount + 1;
}
}
else if (line1[location - 1] == ' ' && line1.length() == location + 4)
{
cout << location + (count * 4)<< endl;
count = count + 1;
line1.erase(location,4);
}
else if (line1[location-1]==' ' && line1[location+4] == ' ')
{
cout << location + (count * 4)<< endl;
count = count + 1;
line1.erase(location,4);
}
else
{
count = count + 1;
line1.erase(location,4);
decount = decount + 1;
}

}
cout << "Total Count = " << count - decount;
_getch();
return 0;
}

You might also like