Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- struct mokinys{
- string name;
- int paz[100];
- int pcount = 0;
- double sum = 0;
- };
- int main()
- {
- mokinys student[100];
- int scount = 0;
- double max = 0;
- char comma;
- ifstream in("Duota2.txt");
- while(!in.eof())
- {
- getline(in, student[scount].name, ',');
- string S;
- getline(in, S);
- int s = 0;
- for(int i = 0; i < S.size(); i++){
- if(S[i] == ' ') continue;
- if(S[i] == ',') {
- student[scount].paz[student[scount].pcount++] = s;
- s = 0;
- }else s = s*10 + S[i] - '0';
- }
- student[scount].paz[student[scount].pcount++] = s;
- in >> ws;
- scount++;
- }
- in.close();
- for(int i = 0; i < scount; i++)
- {
- for(int j = 0; j < student[i].pcount; j++)
- {
- student[i].sum += student[i].paz[j];
- }
- }
- for(int i = 0; i < scount; i++)
- {
- student[i].sum /= double(student[i].pcount);
- if(student[i].sum > max)
- {
- max = student[i].sum;
- }
- }
- ofstream out("Rezultatas.txt");
- for(int i = 0; i < scount; i++)
- {
- if(student[i].sum == max)
- {
- out << student[i].name;
- }
- }
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement