Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

## 配列の中の数を足す

hairetsuplus.cpp
``````#include<iostream>
#include<vector>
using namespace std;

int main(){
vector<int> xs{1,2,3};
vector<int> ys;
for(auto x:xs){
ys.emplace_back(x+10);
}

for(auto y:ys){
cout<<y<<endl;
}
}
``````

11
12
13

hairetsuplus.hs
``````main = print \$ map(+10)[1,2,3]
``````

[11,12,13]

## 配列の合計値を算出

wa.cpp
``````#include<iostream>
#include<vector>
using namespace std;

int main(){
vector<int> xs{1,2,3};
int total = 0;
for(auto x:xs){
total += x;
}
cout<<total<<endl;
}
``````

6

wa.hs
``````main = print \$ foldr (+) 0 [1,2,3]
``````

6

## 配列のある数字以上の数を取り出す

bignumberinsert.cpp
``````#include<iostream>
#include<vector>
using namespace std;

int main(){
vector<int> xs{1,2,3,4,5,6};
vector<int> ys;
for(auto x:xs){
if(x>3){
ys.emplace_back(x);
}
}

for(auto y:ys){
cout<<y<<endl;
}
}
``````

4
5
6

bignumberinsert.hs
``````main = print \$ filter(>3)[1,2,3,4,5,6]
``````

[4,5,6]

## 関数をかけあわせる

kansuu.cpp
``````#include<iostream>
#include<vector>
using namespace std;

int f(int x){return x+10;}

int g(int x){return x*x;}

int main(){
vector<int>xs{1,2,3};
vector<int>ys;
for(auto x:xs){
ys.emplace_back(g(f(x)));
}

for(auto y:ys){
cout<<y<<endl;
}
}
``````

121
144
169

kansuu.hs
``````f x = x+10

g x = x * x

main = print \$ map(g.f)[1,2,3]
``````

[121,144,169]

Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?