Răspuns :
//Problema 1
#include <iostream>
using namespace std;
int main()
{
int n, a[100], max = 0, s = 0, k = 0; //k numara de cate ori apare elementul maxim
cin>>n;
for(int i = 0; i < n; i++)
{
cin>>a[i];
s += a[i];
if(a[i] > a[max])
{
max = i;
k = 1;
}
else if(a[i] == a[max])
k++;
}
cout<<s - a[max] * k;
}
//Problema 2
#include <iostream>
using namespace std;
int main()
{
int a[5][5], s = 0;
for(int i = 0; i < 5; ++i)
for(int j = 0; j < 5; ++j)
cin>>a[i][j];
for(int i = 0; i < 5; ++i)
if(a[i][4 - i] % 2 == 0) s += a[i][4 - i];
cout<<s;
}
//Problema 3
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char s[256];
int cuv = 0;
bool inceput = false;
cin.getline(s, 255);
for(int i = 0; i < strlen(s); ++i)
{
if(s[i] >= 'a' && s[i] <= 'z') inceput = true;
else if(inceput)
{
cuv++;
inceput = false;
}
}
cout<<cuv;
}
#include <iostream>
using namespace std;
int main()
{
int n, a[100], max = 0, s = 0, k = 0; //k numara de cate ori apare elementul maxim
cin>>n;
for(int i = 0; i < n; i++)
{
cin>>a[i];
s += a[i];
if(a[i] > a[max])
{
max = i;
k = 1;
}
else if(a[i] == a[max])
k++;
}
cout<<s - a[max] * k;
}
//Problema 2
#include <iostream>
using namespace std;
int main()
{
int a[5][5], s = 0;
for(int i = 0; i < 5; ++i)
for(int j = 0; j < 5; ++j)
cin>>a[i][j];
for(int i = 0; i < 5; ++i)
if(a[i][4 - i] % 2 == 0) s += a[i][4 - i];
cout<<s;
}
//Problema 3
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char s[256];
int cuv = 0;
bool inceput = false;
cin.getline(s, 255);
for(int i = 0; i < strlen(s); ++i)
{
if(s[i] >= 'a' && s[i] <= 'z') inceput = true;
else if(inceput)
{
cuv++;
inceput = false;
}
}
cout<<cuv;
}
Pentru Pascal
1)
var
i,n,m,c:integer;
a:array [1..10000] of integer;
begin
read(n);
for i:=1 to n do
read(a[i]);
m:=a[1];
for i:=2 to n do
if a[i]>m then m:=a[i];
c:=0;
for i:=1 to n do
if a[i]=m then c:=c+1;
write(c);
end.
2)
var
a:array [1..5,1..5] of integer;
i,j,s:integer;
begin
for i:=1 to 5 do
for j:=1 to 5 do
read(a[i,j]);
s:=0;
for i:=5 downto 1 do
if (a[i,6-i]>0) then s:=s+a[i][6-i];
write(s);
end.
3)
var
a:array [1..1000] of string;
ac:integer;
s:string;
procedure words(s:string);
var
i:integer;
x:string;
begin
s:=s+' ';
ac:=0;
for i:=1 to length(s) do
begin
if (s[i]<>' ') then x:=x+s[i];
if (s[i]=' ') and (length(x)<>0) then
begin
ac:=ac+1;
a[ac]:=x;
x:='';
end;
end;
end;
begin
readln(s);
words(s);
write(ac);
end.
Pentru c++
1)
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,m,c;
cin >> n;
vector <int> a(n);
for (int i=0; i<a.size(); i++)
cin >> a[i];
m=*max_element(a.begin(),a.end());
cout << a.size()-count(a.begin(),a.end(),m);
return 0;
}
2)
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <vector <int> > a(5);
for (int i=0; i<5; i++)
{
a[i].resize(5);
for (int j=0; j<5; j++)
cin >> a[i][j];
}
int s=0;
for (int i=4; i>=0; i--)
if (a[i][4-i]) s+=a[i][4-i];
cout << s;
return 0;
}
3)
#include <vector>
#include <iostream>
using namespace std;
vector <string> words(string s)
{
vector <string> a;
string x;
s+=' ';
for (int i=0; i<s.size(); i++)
{
if (s[i]!=' ') x+=s[i];
if (s[i]==' ' && x!="")
{
a.push_back(x);
x="";
}
}
return a;
}
main()
{
string s;
getline(cin,s);
vector <string> w;
w=words(s);
cout << w.size();
}
1)
var
i,n,m,c:integer;
a:array [1..10000] of integer;
begin
read(n);
for i:=1 to n do
read(a[i]);
m:=a[1];
for i:=2 to n do
if a[i]>m then m:=a[i];
c:=0;
for i:=1 to n do
if a[i]=m then c:=c+1;
write(c);
end.
2)
var
a:array [1..5,1..5] of integer;
i,j,s:integer;
begin
for i:=1 to 5 do
for j:=1 to 5 do
read(a[i,j]);
s:=0;
for i:=5 downto 1 do
if (a[i,6-i]>0) then s:=s+a[i][6-i];
write(s);
end.
3)
var
a:array [1..1000] of string;
ac:integer;
s:string;
procedure words(s:string);
var
i:integer;
x:string;
begin
s:=s+' ';
ac:=0;
for i:=1 to length(s) do
begin
if (s[i]<>' ') then x:=x+s[i];
if (s[i]=' ') and (length(x)<>0) then
begin
ac:=ac+1;
a[ac]:=x;
x:='';
end;
end;
end;
begin
readln(s);
words(s);
write(ac);
end.
Pentru c++
1)
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n,m,c;
cin >> n;
vector <int> a(n);
for (int i=0; i<a.size(); i++)
cin >> a[i];
m=*max_element(a.begin(),a.end());
cout << a.size()-count(a.begin(),a.end(),m);
return 0;
}
2)
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <vector <int> > a(5);
for (int i=0; i<5; i++)
{
a[i].resize(5);
for (int j=0; j<5; j++)
cin >> a[i][j];
}
int s=0;
for (int i=4; i>=0; i--)
if (a[i][4-i]) s+=a[i][4-i];
cout << s;
return 0;
}
3)
#include <vector>
#include <iostream>
using namespace std;
vector <string> words(string s)
{
vector <string> a;
string x;
s+=' ';
for (int i=0; i<s.size(); i++)
{
if (s[i]!=' ') x+=s[i];
if (s[i]==' ' && x!="")
{
a.push_back(x);
x="";
}
}
return a;
}
main()
{
string s;
getline(cin,s);
vector <string> w;
w=words(s);
cout << w.size();
}