File tree 3 files changed +34
-32
lines changed
3 files changed +34
-32
lines changed Original file line number Diff line number Diff line change 5
5
6
6
int main (int argc, char ** argv) {
7
7
8
- // std::cerr << "Map params:";
9
- // for(int i = 0; i < argc; ++i){
10
- // std::cerr << " " << argv[i];
11
- // }
8
+ // std::cerr << "Map params:";
9
+ // for(int i = 0; i < argc; ++i){
10
+ // std::cerr << " " << argv[i];
11
+ // }
12
12
// std::cerr << std::endl;
13
13
14
- std::string str;
15
- std::stringstream sstr;
16
- while (std::cin >> str){
17
- sstr.clear ();
18
- sstr.str (str);
19
- while (sstr >> str){
20
- std::cout << str << " \t " << 1 << std::endl;
21
- }
22
- }
14
+ std::string str, key, value;
15
+ std::stringstream sstr;
16
+ while (std::getline (std::cin, str)){
17
+ int div = str.find (' \t ' );
18
+ key = str.substr (0 , div );
19
+ value = str.substr (div + 1 , str.length () - div - 1 );
20
+ std::cout << value << " \t " << 1 << std::endl;
21
+ }
23
22
}
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ int main(int argc, char** argv) {
25
25
std::cerr << " Reduce:\t path_to_program reduce path_to_reduce_script (script parameters) input_file output_file" << std::endl;
26
26
std::cerr << " Help:\t path_to_program help" << std::endl;
27
27
std::cerr << std::endl;
28
- std::cerr << " Each line of input file for reduce operation must contain tab-separated values: \" key \\ t value\" " << std::endl;
28
+ std::cerr << " Each line of input file must contain tab-separated values: \" key \\ t value\" " << std::endl;
29
29
std::cerr << " Each line of output file will contain tab-separated values: \" key \\ t value\" " << std::endl;
30
30
std::cerr << std::endl;
31
31
return 0 ;
Original file line number Diff line number Diff line change 5
5
6
6
int main (int argc, char ** argv) {
7
7
8
- // std::cerr << "Reduce params:";
9
- // for(int i = 0; i < argc; ++i){
10
- // std::cerr << " " << argv[i];
11
- // }
12
- // std::cerr << std::endl;
8
+ // std::cerr << "Reduce params:";
9
+ // for(int i = 0; i < argc; ++i){
10
+ // std::cerr << " " << argv[i];
11
+ // }
12
+ // std::cerr << std::endl;
13
13
14
- std::string str;
15
- std::string key;
16
- int value;
17
- int result = 0 ;
18
- std::stringstream sstr;
19
- for (; std::getline (std::cin, str);){
20
- sstr.clear ();
21
- sstr.str (str);
22
- sstr >> key;
23
- sstr >> value;
24
- result += value;
25
- }
26
- std::cout << key << " \t " << result << std::endl;
14
+ std::string str;
15
+ std::string key;
16
+ std::string value;
17
+ int val;
18
+ int result = 0 ;
19
+ std::stringstream sstr;
20
+ for (; std::getline (std::cin, str);){
21
+ int div = str.find (' \t ' );
22
+ key = str.substr (0 , div );
23
+ value = str.substr (div + 1 , str.length () - div - 1 );
24
+ sstr.clear ();
25
+ sstr.str (value);
26
+ sstr >> val;
27
+ result += val;
28
+ }
29
+ std::cout << key << " \t " << result << std::endl;
27
30
}
You can’t perform that action at this time.
0 commit comments