Рабочий стол > DL Руководство пользователя > Функции и процедуры > Information > Сравнить страницу
Функции и процедуры Войти | Зарегистрироваться   Просмотр версии для печати текущей страницы.

Ключ
Эти линии были удалены. Это слово было удалено.
Эти линии были добавлены. Это слово было добавлено.

Просмотр истории страницы


Есть 27 изменений. Просмотреть первое изменение .

 *1. Решение задачи с функцией - Слова массива, состоящие из различных букв*
  
 _\#include <bits/stdc++.h>_
 _using namespace std;_
  {code:title=razl_bukvi.cpp\|borderStyle=solid}\#include <bits/stdc++.h>using namespace std;
  
_string Razl(string s)_
 \{
  string Razl(string s)
  {
  string w;
  int d,j;
  
string w;
   d=s.length();
  w=s[0];
  for (j=1; j<d; j++)
  if (w.find(s[j])>d) w+=s[j];
  return w;
  }
  
int d,j;
  
 d=s.length();
  
 w=s\[0\];
  
 for (j=1; jd) &nbsp;w+=s\[j\];
  
 return w;&nbsp;
  
 \}
 \\
  
 _int main()_
 _{_
 _string s\[100\];_
 _int n,i;_
 _cin >> n;_
 _for (i=0; i<n; i++) cin >> s{_}_\[i\]__;_
 _for (i=0; i<n; i++)_
 _if (Razl(s{_}_\[i\]__)==s{_}_\[i\]__) cout << s\[i\] << endl;_
 _}_
  
 *2. Решение задачи с процедурой*
  int main()
 {
  string s[100];
  int n,i;
  cin >> n;
  for (i=0; i<n; i++) cin >> s[i];
  for (i=0; i<n; i++)
  if (Razl(s[i])==s[i]) cout << s[i] << endl;
 }{code}{*}2. Решение задачи с процедурой*
 Предложение => массив слов
  
_\#include <bits/stdc++.h>_
 _using namespace std;_
  {code:title=predloch-massiv.cpp\|borderStyle=solid}\#include <bits/stdc++.h>using namespace std;
  
_string s,m{_}_\[100\]__;_
 _int n;_
  string s,m[100];
 int n;
  
_void Razbit()_
 \{ string p; &nbsp; &nbsp;int i,d; &nbsp; &nbsp;s+=' &nbsp;'; &nbsp; &nbsp;d=s.length(); &nbsp; &nbsp;n=0; &nbsp; &nbsp;p=""; &nbsp;&nbsp;for (i=0; i<d; i+)if (s\[i\]\!=' ') p=s\[i\];else \{m\[n\]=p;n++;p="";\}\}
  void Razbit()
  {
  string p;
  int i,d;
  s+=' '; d=s.length(); n=0; p="";
  for (i=0; i<d; i++)
  if (s[i]!=' ') p+=s[i];
  else {
  m[n]=p;
  n++;
  p="";
  }
  }
  
int main()&nbsp;
  int main()
 {
  getline(cin,s);
  Razbit();
  for (int i=0; i<n; i++) cout << m[i] << endl;
 }{code}{*}3. Булевая функция, получает в качестве параметра целое x*
  
&nbsp;{ getline(cin,s);
 Razbit();
 for (int i=0; i<n; i++) cout << m\[i\]&nbsp;&nbsp;<< endl;
 }
  
 *3. Булевая функция, получает в качестве параметра целое x*
  
 *Количество простых, кубы которых меньше n*
  
_\#include <bits/stdc++.h>_
 _using namespace std;bool Prime(int x)_
  {code:title=kubi<n.cpp\|borderStyle=solid}\#include <bits/stdc++.h>using namespace std;
  
_bool Prime(int x) \{ for (int i=2; i<x; i++) &nbsp; &nbsp; if ((x%i)==0) &nbsp; &nbsp; return false; &nbsp; return true; \}_
 _int main()_
 _{_
 _string is,s;_
 _int n,x,ans;_
 _cin >> n;_
 _ans=0;_
 _for (x=2; x*x*x<n; x++)_
 _if (Prime) ans++;_
 _cout << ans;_
 _}_
 _/\*_
 _1001 - 4_
 _126 - 3_
 _125 - 2_
 _10 - 1_
 _7 - 0_
 _\*/&nbsp;_
  bool Prime(int x)
  {
  for (int i=2; i<x; i++)
  if ((x%i)==0) return false;
  return true;
  }
  
*4. Возвращение значений параметров из процедуры Split*
  int main()
 {
  string is,s;
  int n,x,ans;
  cin >> n;
  ans=0;
  for (x=2; x*x*x<n; x++)
  if (Prime(x)) ans++;
  cout << ans;
 }
  
/*
 1001 - 4
 126 - 3
 125 - 2
 10 - 1
 7 - 0
 */{code}{*}4. Возвращение значений параметров из процедуры Split*
  
 &x1 - передаём в процедуру адрес переменной x1
  
_\#include <bits/stdc++.h>_
 _using namespace std;_
  {code:title=split.cpp\|borderStyle=solid}\#include <bits/stdc++.h>using namespace std;
  
_void Split(int x, int &x1, int &x2, int &x3)_
 _\{_
 _x1=x%10;_
 _x3=x/100;_
 _x2=(x/10) % 10;_
 _\}_
  void Split(int x, int &x1, int &x2, int &x3)
  {
  x1=x%10;
  x3=x/100;
  x2=(x/10) % 10;
  }
  
_int main()_
 _\{_
 _int i,i1,i2,i3,_
 _j,j1,j2,j3,_
 _n,a2,a3;_
 _cin >> n;_
 _a2=0;_
 _for (i=10; i<100; i++)_
 _for (j=10; j<100; j++)_
 _\{_
 _i1=i/10; i2=i%10;_
 _j1=j/10; j2=j%10;_
 _if ((i1+i2==j1+j2) && (abs(i-j)>a2))_
 _a2=abs(i-j);_
  int main()
 {
  int i,i1,i2,i3,
  j,j1,j2,j3,
  n,a2,a3;
 cin >> n;
  a2=0;
 for (i=10; i<100; i++)
 for (j=10; j<100; j++)
 {
  i1=i/10; i2=i%10;
  j1=j/10; j2=j%10;
 if ((i1+i2==j1+j2) && (abs(i-j)>a2))
  a2=abs(i-j);
  
_\};_
 _if (n==2) cout << a2;_
 _a3=0;_
 _for (i=100; i<1000; i++)_
 _for (j=100; j<1000; j++)_
 _\{_
 _Split(i,i1,i2,i3);_
 _Split(j,j1,j2,j3);_
 _if (((i1+i2+i3)==(j1+j2+j3)) && (abs(i-j)>a3))_
 _a3=abs(i-j);_
 _\};_
 _if (n==3) cout << a3;_
 _\}_
  };
 if (n==2) cout << a2;
  a3=0;
 for (i=100; i<1000; i++)
 for (j=100; j<1000; j++)
 {
  Split(i,i1,i2,i3);
  Split(j,j1,j2,j3);
 if (((i1+i2+i3)==(j1+j2+j3)) && (abs(i-j)>a3))
  a3=abs(i-j);
 };
 if (n==3) cout << a3;
 }{code}{*}5. Три лучших рейтинга (10_BY. Спартакиада)*
  
*5. Три лучших рейтинга (10_BY. Спартакиада)*
  {code:title=spartakiada.cpp\|borderStyle=solid}\#include <bits/stdc++.h>using namespace std;
  
\#include <bits/stdc++.h>
 using namespace std;
  int r[100000],n;
  
int r\[100000\],n;
  
 int nMaxR()
\{
 int max,i,num;
 max=0;
 for (i=0; i<n; i++)
 if (r\[i\]>max)
 \{ max=r\[i\]; num=i; \};
 return num;
 \}
 \\
   {
 int max,i,num;
 max=0;
 for (i=0; i<n; i++)
  if (r[i]>max) { max=r[i]; num=i; };
  return num;
  }
  
 int main()
\{
 int x,y,z,a,b,c,i,n1,n2,n3;
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 cin >> x >> y >> z;
 cin >> n;
 for (i=0; i<n; i++)
 \{
 cin >> a >> b >> c;
 r\[i\]=a*x+b*y+c*z;
 \}
 n1=nMaxR(); r\[n1\]=0;
 n2=nMaxR(); r\]n2\]=0;
 n3=nMaxR();
 cout << n1+1 << ' ' << n2+1 << ' ' << n3+1;
 \}
  {
 int x,y,z,a,b,c,i,n1,n2,n3;
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 cin >> x >> y >> z;
 cin >> n;
 for (i=0; i<n; i++)
 {
 cin >> a >> b >> c;
  r[i]=a*x+b*y+c*z;
 }
 n1=nMaxR(); r[n1]=0;
 n2=nMaxR(); r[n2]=0;
 n3=nMaxR();
 cout << n1+1 << ' ' << n2+1 << ' ' << n3+1;
 }{code}{*}6. Функция и процедура (2010_BY. Бактериалное родство)*
  
*6. Функция и процедура (2010_BY. Бактериалное родство)*
  {code:title=bakterrodstvo.cpp\|borderStyle=solid}\#include <bits/stdc++.h>using namespace std;
  
\#include <bits/stdc++.h>
 using namespace std;
  
 string a,b;
 int n;
  
 int Degree()
\{
 int i,k;
 k=0;
 for (i=0; i<n; i++)
 if (a\[i\]==b\[i\]) k++;
 return k;
 \}
   {
 int i,k;
 k=0;
 for (i=0; i<n; i++)
 if (a[i]==b[i]) k++;
 return k;
  }
 void Shift()
\{
 a=a\[n-1\]+a.substr(0,n-1);
 \}
   {
  a=a[n-1]+a.substr(0,n-1);
  }
  
 int main()
 \{
 int i,max,k;
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 cin >> n;
 cin >> a;
 cin >> b;
 max=0;
 for (i=0; i<n; i++)
 \{
 k=Degree();
 if (k>max) max=k;
 Shift();
 \}
 cout << max;
 \}
  {
 int i,max,k;
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 cin >> n;
 cin >> a;
 cin >> b;
 max=0;
 for (i=0; i<n; i++)
 {
 k=Degree();
 if (k>max) max=k;
 Shift();
 }
 cout << max;
 }{code}
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: http://www.atlassian.com/software/confluence Build:#2.6.1 916) - Ошибка/новая особенность - Свяжитесь с Администраторами