| 1234567891011121314151617181920212223242526272829303132333435 |
- #include <cstdlib>
- #include <fstream>
- #include <string>
- using namespace std;
- int main(){
- int addend = 0, sum = 0, i = 0; // initialize variables
- string word = ""; // initialize string object
- ifstream fin ("input.txt"); // input file at ./input.txt
- ofstream fout ("output.txt"); // create or overwrite output file at ./output.txt
-
- while (fin >> addend){ // run until end of file / get first int
- sum = 0; // reset the sum for each word
- sum += addend; // add first int to sum
- fin.ignore(); // skip the first comma
-
- fin >> addend; // get second int
- sum += addend; // add second int to sum
- fin.ignore(); // skip the second comma
-
- fin >> addend; // get third int
- sum += addend; // add third int to sum
- fin.ignore(); // skip the \n
-
- getline(fin, word); // get the word on the line below its ints
-
- for (i = 0; i < sum - 1; i++){ // for each specified time
- fout << word << ","; // print the word with a comma
- } fout << word << endl; // no comma at the end
- }
-
- fin.close();
- fout.close();
- }
|