Сначала нужно найти объем одного пикселя. Переведём объем изображения в биты и разделим на количество пикселей
На один пиксель отводится 4 бит, количество цветов равно
Ответ: 16 цветов.
#include <iostream>
<span>#include <ctime>
</span><span>using namespace std;
</span>int main() {
<span> int n,m;
</span><span> FILE *fpt;
</span><span> cout<<"n = "; cin>>n;
</span><span> fpt=fopen("input.dat","wb");
</span><span> srand(time(NULL));
</span><span>// запись файла
</span><span> for (int i=0; i<n; i++) {
</span><span> m=rand()%8000-3000;
</span><span> cout<<m<<" ";
</span><span> fwrite(&m,sizeof(int),1,fpt);
</span><span> }
</span><span> cout<<endl;
</span><span> fclose(fpt);
</span><span> fpt=fopen("input.dat","rb+");
</span><span> int indf=0,indl=0,vf=0,vl=0,k=0;
</span><span>// чтение файла
</span><span> while (fread(&m,sizeof(int),1,fpt)!=0) {
</span><span> k++;
</span><span> if (!(m%2==0) && (indf==0)) { indf=k-1; vf=m; }
</span><span> if ((!m==0) && (m%2==0)) { indl=k-1; vl=m; }
</span><span> }
</span><span> cout<<"first odd = "<<vf<<" index = "<<indf<<endl;
</span><span> cout<<"last even = "<<vl<<" index = "<<indl<<endl;
</span><span>// обмен первого нечетного и последнего четного
</span><span> if (indf>0) {
</span><span> fseek(fpt,sizeof(int)*indf,SEEK_SET);
</span><span> fwrite(&vl,sizeof(int),1,fpt);
</span><span> }
</span><span> if (indl>0) {
</span><span> fseek(fpt,sizeof(int)*indl,SEEK_SET);
</span><span> fwrite(&vf,sizeof(int),1,fpt);
</span><span> }
</span><span> fclose(fpt);
</span><span> system("pause");
</span><span> return 0;
</span><span>}
</span>n = 6
<span>4368 2733 1112 2620 1941 753
</span><span>first odd = 2733 index = 1
</span><span>last even = 2620 index = 3
</span>
Не люблю сишные приколы, даже не стал ковырять в коде. Я бы так написал:
1. Листинг программы:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream f("words.txt");
int MAX_WORD = 6;
if(!f.is_open())
{
cout <<"Ошибка открытия файла!" <<endl;
return 1;
}
string str;
int line=1;
int len=0, cnt=0;
while(!f.eof())
{
getline(f, str);
for(int i=0; i!=str.length(); ++i)
{
if(str[i]!=' ')
++len;
else
{
if(len<=MAX_WORD)
{
++cnt;
len=0;
}
else
len=0;
}
}
cout <<line <<". Коротких слов: " <<cnt <<endl;
cnt=0;
++line;
}
return 0;
}
2. Тестовый файл:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vehicula tortor nec enim dictum, quis accumsan quam ultricies.
Maecenas suscipit urna sed leo pellentesque pellentesque. Donec lorem libero, mattis ac lobortis et, porta ac felis. Pellentesque at dui sollicitudin mauris cursus dignissim.
Integer aliquam metus eu ligula rutrum, non ultricies libero molestie. Proin posuere ante velit, quis luctus arcu efficitur a.
Suspendisse sed interdum dolor.
Integer laoreet, mi non pulvinar sagittis, leo mi semper mauris, sed fermentum est lorem sed neque.
Duis neque justo, facilisis at magna quis, molestie varius dolor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Aenean at nulla massa. Proin interdum turpis justo, ac ultricies mauris molestie vitae. In erat augue, elementum in placerat vitae, venenatis quis metus.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Integer hendrerit interdum tellus, sit amet porttitor diam consequat quis.
Vivamus dignissim aliquam ex, eu maximus augue commodo a. Morbi molestie convallis urna ac faucibus. Mauris eget aliquet est. Nulla luctus fringilla magna, ut viverra elit porta sit amet.
Curabitur at tortor eget dolor tincidunt iaculis. Praesent odio libero, vestibulum lobortis est id, porta aliquam tortor.
Quisque fringilla nibh ut tellus dignissim, at pulvinar mauris faucibus.
Suspendisse eu metus vestibulum, vestibulum ligula sed, pharetra tellus. Etiam ultrices consectetur congue. Nulla at dignissim urna. Sed pretium augue ipsum, in egestas massa tempor sed.
Ut id tincidunt lacus, tristique hendrerit arcu. Quisque ultrices sem consectetur risus gravida, nec tristique tellus egestas. Nunc eleifend non diam elementum scelerisque.
In ac dui in neque euismod volutpat eu sit amet metus. Donec iaculis leo urna, ut mattis est commodo in. Phasellus sollicitudin, ante sit amet rhoncus dignissim, velit mauris
scelerisque neque, posuere ultrices ante augue eget libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
Morbi metus nulla, tincidunt vitae congue id, sollicitudin et neque. Maecenas suscipit vel sapien hendrerit lobortis. In feugiat nulla massa.
Fusce nec gravida nunc. Integer nec odio a eros luctus auctor. Fusce blandit quam id dolor vestibulum feugiat. Cras tincidunt id felis ac ultricies. Proin feugiat hendrerit feugiat.
Vestibulum congue leo ex, pulvinar sagittis ipsum venenatis eu. In vitae dolor in odio lacinia laoreet. Vivamus eget rhoncus felis. Nulla ullamcorper lorem quis ultrices iaculis.
Aliquam facilisis mattis lacus. Morbi et volutpat odio. Sed posuere, odio at faucibus dapibus, ex nisl auctor elit, et vehicula lectus ex sit amet lectus.
Pellentesque viverra dignissim urna et feugiat. Nunc vitae justo nec ex vehicula dapibus. Ut sed sem laoreet, sollicitudin dui fermentum, congue velit.
In interdum augue velit, a viverra lectus porta eu. Curabitur malesuada placerat lobortis. Praesent ullamcorper ullamcorper elit, eget mollis dolor.
Vestibulum malesuada accumsan leo, non maximus nisl. Donec nec nunc tellus. Fusce volutpat hendrerit urna, et egestas nibh vestibulum eget.
Cras pharetra rutrum libero non blandit.
3. Прогон программы:
(см. скриншот).
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
int main()
{
std::string abc = "abcdefghijklmnopqrstuvwxyz";
std::string name;
std::cin >> name;
for (const char &character : name)
{
abc.erase(std::remove(abc.begin(), abc.end(), tolower(character)), abc.end());
}
for (const char &character : abc)
{
std::cout << character << ' ';
}
std::cout << std::endl;
return 0;
}