0% found this document useful (0 votes)
2 views3 pages

code

The document contains a C++ program that processes a series of input strings to perform calculations based on the presence of specific symbols and digits. It uses vectors to store inputs and symbols, and applies logic to modify the strings and compute a sum based on the parsed numbers. The program outputs the final computed sum after processing all input lines.

Uploaded by

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

code

The document contains a C++ program that processes a series of input strings to perform calculations based on the presence of specific symbols and digits. It uses vectors to store inputs and symbols, and applies logic to modify the strings and compute a sum based on the parsed numbers. The program outputs the final computed sum after processing all input lines.

Uploaded by

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

#include <iostream>

#include <vector>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <cmath>
using namespace std;

void day3() {
string input1;
vector <string> inputs = { };
vector <char> symbols = { '*','+','-','=','$','&','@','^','%' ,'#' };
vector <int> currentnumber = {};
vector <int> leftoverindex = {};
int power = 0;
int sum = 0;
int testsum = 0;
bool overload = false;
int size;
cout << "Size: ";
cin >> size;

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

getline(cin, input1);
inputs.push_back(input1);
}
for (int i = 0; i < inputs.size(); i++) { // B is a half symbol, it only
affects the current line

for (int element = 0; element < inputs[i].size(); element++) {


if (i + 1 < inputs.size()) {
if (find(symbols.begin(), symbols.end(), inputs[i + 1][element]) !=
symbols.end()) {

if (isdigit(inputs[i][element]) == false) {

inputs[i][element] = 'B';

}
else if (element == inputs[i].size() - 1) {
inputs[i].push_back('B');
}
else if (element == 0) {
inputs[i] = 'B' + inputs[i];
}
else {
for (int b = 0; element + b < inputs[i + 1].size() ||
inputs[i + 1][element + b]; b++) {
if (inputs[i][element + b] == '.') {
inputs[i][element + b] = 'B';
break;
}
if (find(symbols.begin(), symbols.end(), inputs[i]
[element + b]) != symbols.end()) {
break;
}
if (element + b == inputs[i + 1].size() - 1) {
inputs[i].push_back('B');
break;
}
}
}
}
}
if (find(symbols.begin(), symbols.end(), inputs[i][element]) !=
symbols.end() || inputs[i][element] == 'B') {
if (element + 1 > inputs[i].size()) {
overload = true;
}
if (isdigit(inputs[i][element + 1]) && overload == false) {
for (int b = 0; (isdigit(inputs[i][element + b]) || b == 0) &&
element + b < inputs[i].size(); b++) {

if (b > 0) {

currentnumber.push_back(inputs[i][element + b] - '0');
inputs[i][element + b] = '.';
power = b - 1;
}

for (int counter = 0; counter < currentnumber.size(); counter+


+) {
if (i == 9) {

sum += currentnumber[counter] * pow(10, power - counter);


}

testsum = sum;
power = 0;
currentnumber = {};
}
if (element - 1 > 0) {
if (isdigit(inputs[i][element - 1])) {
for (int b = 0; (isdigit(inputs[i][element - b]) || b == 0)
&& element - b >= 0; b++) {
if (b > 0) {

currentnumber.push_back(inputs[i][element - b] -
'0');

}
if (element - b == 0) {
break;
}
}

for (int counter = 0; counter < currentnumber.size();


counter++) {

if (i == 9) {
}
sum += currentnumber[counter] * pow(10, counter);
}

testsum = sum;
currentnumber = {};
}
}

if (i + 1 < inputs.size()) {

if (find(symbols.begin(), symbols.end(), inputs[i + 1]


[element]) == symbols.end() && inputs[i][element] != 'B') {
if (isdigit(inputs[i + 1][element]) == false)
inputs[i + 1][element] = 'B';
else if (element == inputs[i + 1].size() - 1) {
inputs[i + 1].push_back('B');
}
else if (element == 0) {
inputs[i + 1] = 'B' + inputs[i + 1];
}
else {
for (int b = 0; element + b < inputs[i + 1].size() ||
inputs[i + 1][element + b]; b++) {
if (inputs[i + 1][element + b] == '.') {
inputs[i + 1][element + b] = 'B';
break;
}
if (element + b == inputs[i + 1].size() - 1) {
inputs[i + 1].push_back('B');
break;
}
}

}
}

}
}

cout << sum;


}

int main()
{
day3();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy