C++ arrays
#include <stdio.h>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
using namespace std;
int main()
{
ifstream fin ("text.in");
int n;
fin >> n;
int *array = new int[3];
cout << " array " << endl;
for ( int i = 0; i < 3; i++ ) {
// array[i] = new int[n];
cout << array[i] << endl;
}
cout << endl;
int** ary = new int*[3];
for ( int i = 0; i < 3; i++ ) {
ary[i] = new int[n];
cout << ary[i][0];
}
for ( int i = 0; i<3; i++ ) {
delete [] ary[i];
}
typedef int ARR1[2];
int (*arr)[2] = new int[3][2];
ARR1* arrtype = new ARR1[3];
int ***arr3 = new int **[2];
int **arrr = new int*[4];
// auto arrauto = 4;
auto arrauto = new int[4][2];
printf("n %d\n", n);
cout << "n: " << n << endl;
auto ary2 = new int[5001](); // initialize all elements with 0
fill_n (ary2, 5001, 3); // initialize all elements with (int)3
// c style, cstring use memset (ary2, 0, n*sizeof(int));
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream fin ("game.in");
int num_of_cup = 3;
int n;
fin >> n;
auto ary = new int*[n];
for ( int i = 0; i < n; i++ ) {
ary[i] = new int[3];
for ( int j = 0; j < 3; j++ ) {
fin >> ary[i][j];
}
}
int maxpoint = 0;
for (int i = 1; i < num_of_cup + 1; i++) {
int point = 0;
int current = i;
for (int j = 0; j < n; j++) {
if (ary[j][0] == current) {current = ary[j][1];}
else if (ary[j][1] == current) {current = ary[j][0];}
if (ary[j][2] == current) {point++;}
}
maxpoint = max( maxpoint, point );
}
cout << maxpoint << endl;
return 0;
}
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream fin ("sleepysort.in");
int n;
fin >> n;
auto animal = new int[n];
auto animal_name = new string[n];
auto animal_is = new string*[n];
for (int i = 0; i < n; i++) {
string s;
int k;
fin >> s;
fin >> k;
for (int j = 0; j < k; j++) {
fin >> s;
cout << s << " ";
}
cout << endl;
// fin >> animal_name[i];
}
}
Using <vector>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
ifstream fin ("guess.in");
int n;
fin >> n;
// auto animal = new int[n];
auto animal_name = new string[n];
auto animal_is = new string*[n];
// pair<int,int> animal_has[n];
// pair<string,int> *guess_has;
// vector<pair<string,int>> guess_has;
vector<string> has;
vector<pair<int,string>> has_vec;
// auto has_name = new string[101];
// auto has_count = new int[101];
string has_name[101];
int has_count[101];
for (int i=0; i < n; i++) {
int k;
fin >> animal_name[i];
fin >> k;
animal_is[i] = new string[k];
for (int j = 0; j < k; j++) {
fin >> animal_is[i][j];
// guess_has.push_back( make_pair(animal_is[i][j], 1) );
has.push_back( animal_is[i][j] );
// cout << animal_is[i][j] << " ";
}
}
sort( has.begin(), has.end() );
string last_name = "";
int index = 0;
for (auto i : has) {
if (last_name == i) {
// cout << index << " same** " << i << " " << last_name << endl;
has_count[index]++;
// cout << index << " " << has_name[index] << " " << has_count[index] << endl;
} else {
// cout << index << " " << i << " " << last_name << endl;
index ++;
has_name[index] = i;
has_count[index] = 1;
last_name = i;
// cout << index << " " << has_name[index] << " " << has_count[index] << endl;
}
}
for (int i = 0; i < 101; i++) {
if (has_count[i] > 0) { has_vec.push_back( make_pair( has_count[i], string(has_name[i]) ) ); }
// if (has_count[i] > 0) { cout << i << " " << has_count[i] << " " << has_name[i] << endl; }
}
sort( has_vec.begin(), has_vec.end(), greater<>() );
for (auto i : has_vec) {
cout << i.first << " " << i.second << endl;
int n = i.first;
for
for (int i=0; i<3; i++) {
}
}
cout << endl;
return 0;
}
No comments:
Post a Comment