记单词
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
英语考试就要到了,哈士奇决定在考试前的这段时间里每天背一些单词,他找到来一本乱序的单词书,为了方便记忆,哈士奇决定先给这本单词书重新按照字典序排序,然后把单词分成若干组,每天背诵一组,但是单词的数量实在是太多了,于是他决定编程解决这个问题。
已知书中共有 N 个单词,哈士奇每天计划背诵 M 个单词,请根据所给单词列出详细的学习计划。
Input
第一行包含两个正整数 N,M(1 <= N <= 1000,1 <= M <= N),表示书中共有 N 个单词,哈士奇每天计划背 M 个,且 N 为 M 的整数倍。
第二行包含 N 个 用空格隔开的只包含小写字母的字符串,每个单词不超过10个字符,表示 N 个单词。
Output
第一行包含一个正整数 T,表示分成 T 组。
接下来 T 行每行包含 M 个字符串,表示该组需要记忆的单词。
Sample Input
10 5 apple boy city tree girl orange pink red banana blue
Sample Output
2 apple banana blue boy city girl orange pink red tree
Hint
Source
Miracle_QSH
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
string a[1011];
scanf("%d%d",&n,&m);
for(int i=0; i<n; i++)
cin>>a[i];
sort(a,a+n);
printf("%d\n",n/m);
int x=m;
for(int i=0; i<n; i++)
{
if((i+1)==m)
{
m+=x;
cout<<a[i]<<endl;
}
else cout<<a[i]<<" ";
}
return 0;
}