URI Online Judge | 1258
T-Shirts
By Neilor Tonin, URI Brasil
Timelimit: 1
Professor Rolien and their Computer Science students are making a polo shirt that need to be both beautiful and inexpensive. After some meetings, it was agreed with the students that would be made only black shirts but the students could choose between the color details (white or red). Therefore, Rolien needs your help to arrange the lists for all classes for those that want to by the shirt, relating these shirts by color details, size (P: small), M or (G:large) and lastly by name.
Input
The input contains several test cases. Each test case begins with a integer and positive N (1 ≤ N ≤ 60), that indicates the amount of shirts that will be made for that class. The next N*2 lines contains information of each shirt (will be two lines of information for each shirt). The first line will contain the student's name and the second line will contain the color of the shirt details ("branco" -white or "vermelho" -red) followed by a space and the size of the shirt "P" "M" or "G". The input ends when the value of N equals zero (0) and this number should not be processed.
Output
For each test case print the information sorted by color details in ascending order, followed by size in descending order and at last, by name in ascending order, as shown below.
Note: should be printed a blank line between two test cases.
Sample Input | Sample Output |
9 Maria Jose branco P Mangojata Mancuda vermelho P Cezar Torres Mo branco P Baka Lhau vermelho P JuJu Mentina branco M Amaro Dinha vermelho P Adabi Finho branco G Severina Rigudinha branco G Carlos Chade Losna vermelho P 3 Maria Joao branco P Marcio Guess vermelho P Maria Jose branco P 0 | branco P Cezar Torres Mo branco P Maria Jose branco M JuJu Mentina branco G Adabi Finho branco G Severina Rigudinha vermelho P Amaro Dinha vermelho P Baka Lhau vermelho P Carlos Chade Losna vermelho P Mangojata Mancuda branco P Maria Joao branco P Maria Jose vermelho P Marcio Guess |
URI solution 1258 | T-Shirts in C++
#include <iostream>
#include <cstring>
#include <algorithm>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
using
namespace
std;
typedef
struct
{
string nome, cor, tam;
}aluno;
aluno arr[61];
bool
cmp(aluno a, aluno b)
{
if
(a.cor == b.cor){
if
(a.tam == b.tam)
return
a.nome < b.nome;
else
return
a.tam > b.tam;
}
else
{
return
a.cor < b.cor;
}
}
int
main(
int
argc,
char
const
*argv[])
{
int
n;
string s;
cin >> n;
while
(n)
{
cin.ignore();
FOR(i, n)
{
getline(cin, arr[i].nome);
cin >> arr[i].cor >> arr[i].tam;
cin.ignore();
}
stable_sort(arr, arr + n, cmp);
FOR(i, n)
cout << arr[i].cor <<
" "
<< arr[i].tam <<
" "
<< arr[i].nome <<
'\n'
;
cin >> n;
if
(n != 0)
cout <<
'\n'
;
}
return
0;
}
For further problem, comment below..
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks