Skip to content
Snippets Groups Projects
Commit 7b55ede0 authored by Sandipan Mohanty's avatar Sandipan Mohanty
Browse files

Adjust some examples in chapter 6

parent e7824291
Branches
No related tags found
No related merge requests found
A solar flare is a relatively intense, localized emission of
electromagnetic radiation in the Sun's atmosphere. Flares
occur in active regions and are often, but not always,
accompanied by coronal mass ejections, solar particle events,
and other eruptive solar phenomena. The occurrence of solar
flares varies with the 11-year solar cycle.
Solar flares are thought to occur when stored magnetic energy
in the Sun's atmosphere accelerates charged particles in the
surrounding plasma. This results in the emission of
electromagnetic radiation across the electromagnetic spectrum.
The extreme ultraviolet and x-ray radiation from solar flares
is absorbed by the daylight side of Earth's upper atmosphere,
in particular the ionosphere, and does not reach the surface.
This absorption can temporarily increase the ionization of
the ionosphere which may interfere with short-wave radio
communication. The prediction of solar flares is an active
area of research.
Flares also occur on other stars, where the term stellar
flare applies.
#include <fstream> #include <fstream>
#include <iomanip> #include <print>
#include <iostream>
#include <map> #include <map>
#include <string> #include <string>
...@@ -14,8 +13,6 @@ auto main(int argc, char* argv[]) -> int ...@@ -14,8 +13,6 @@ auto main(int argc, char* argv[]) -> int
freq[s]++; freq[s]++;
for (auto&& [word, count] : freq) for (auto&& [word, count] : freq)
std::cout << std::setw(12) << word std::print("{:20} :{:12}\n",
<< std::setw(4) << ':' word, count);
<< std::setw(12) << count
<< "\n";
} }
#include <fstream>
#include <format>
#include <ranges>
#include <print>
#include <map>
#include <string>
namespace sr = std::ranges;
namespace sv = sr::views;
auto main(int argc, char* argv[]) -> int
{
std::ifstream fin(argv[1]);
std::map<std::string, unsigned> freq;
std::string s;
auto non_alphabetic = [](auto c) { return not isalpha(c); };
while (fin >> s) {
auto s2 = s | sv::drop_while(non_alphabetic)
| sv::reverse
| sv::drop_while(non_alphabetic)
| sv::reverse
| sr::to<std::string>();
freq[s2]++;
}
for (auto&& [word, count] : freq)
std::print("{:20} :{:12}\n", word, count);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment