L1-030. 一帮一

一帮一分组算法

L1-030. 一帮一
“一帮一学习小组”是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作,即在得到全班学生的排名后,在当前尚未分组的学生中,将名次最靠前的学生与名次最靠后的异性学生分为一组。

输入格式:

输入第一行给出正偶数N(<=50),即全班学生的人数。此后N行,按照名次从高到低的顺序给出每个学生的性别(0代表女生,1代表男生)和姓名(不超过8个英文字母的非空字符串),其间以1个空格分隔。这里保证本班男女比例是1:1,并且没有并列名次。

输出格式:

每行输出一组两个学生的姓名,其间以1个空格分隔。名次高的学生在前,名次低的学生在后。小组的输出顺序按照前面学生的名次从高到低排列。

输入样例:
8
0 Amy
1 Tom
1 Bill
0 Cindy
0 Maya
1 John
1 Jack
0 Linda
输出样例:
Amy Jack
Tom Linda
Bill Maya
Cindy John.

解题思路:
因为输入顺序就是排名的顺序,所以不需要另外记录排名的变量,直接按照输入顺序即下标来遍历,每一组分别从前和从后开始遍历,每一组的第一个输出只要是没有输出过的,不需要考虑性别,第二个输出要考虑性别和是否输出。每输出一个计数,直到输出完n个为止。

#include<cstdio>
struct student{
    int sex;
    char name[10];
    bool print;
}stu[80];
int main(){
    int n,cnt=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d %s",&stu[i].sex ,stu[i].name );
        stu[i].print =false;
    }
    while(cnt<n){
        int i,j;
        for(i=1;i<=n;i++){
            if(stu[i].print ==false){
                printf("%s ",stu[i].name );
                stu[i].print =true;
                cnt++;
                break;
            }
        }
        for(j=n;j>=1;j--){
            if(stu[j].print ==false&&stu[j].sex !=stu[i].sex ){
                printf("%s\n",stu[j].name );
                stu[j].print =true;
                cnt++;
                break;
            }
        }
    }
    return 0;
}
我有个python封装成的exe文件,我想从源文件看看它是怎么实现的。帮我看下这个文件目录,我应该从何下手: E:. │ ble.py │ ble.spec │ BleakUWPBridge.dll │ bt_ctrl.py │ bt_ctrl.spec │ test_ble.py │ test_ble.spec │ 蓝牙控制程序说明.docx │ ├─.idea │ │ .gitignore │ │ bluetooth.iml │ │ misc.xml │ │ modules.xml │ │ workspace.xml │ │ │ └─inspectionProfiles │ profiles_settings.xml │ ├─build │ └─test_ble │ Analysis-00.toc │ base_library.zip │ COLLECT-00.toc │ EXE-00.toc │ PKG-00.toc │ PYZ-00.pyz │ PYZ-00.toc │ test_ble.exe │ test_ble.exe.manifest │ test_ble.pkg │ Tree-00.toc │ warn-test_ble.txt │ xref-test_ble.html │ ├─dist │ │ ble.exe │ │ test_ble.zip │ │ │ └─test_ble │ │ api-ms-win-core-console-l1-1-0.dll │ │ api-ms-win-core-datetime-l1-1-0.dll │ │ api-ms-win-core-debug-l1-1-0.dll │ │ api-ms-win-core-errorhandling-l1-1-0.dll │ │ api-ms-win-core-file-l1-1-0.dll │ │ api-ms-win-core-file-l1-2-0.dll │ │ api-ms-win-core-file-l2-1-0.dll │ │ api-ms-win-core-handle-l1-1-0.dll │ │ api-ms-win-core-heap-l1-1-0.dll │ │ api-ms-win-core-interlocked-l1-1-0.dll │ │ api-ms-win-core-libraryloader-l1-1-0.dll │ │ api-ms-win-core-localization-l1-2-0.dll │ │ api-ms-win-core-memory-l1-1-0.dll │ │ api-ms-win-core-namedpipe-l1-1-0.dll │ │ api-ms-win-core-processenvironment-l1-1-0.dll │ │ api-ms-win-core-processthreads-l1-1-0.dll │ │ api-ms-win-core-processthreads-l1-1-1.dll │ │ api-ms-win-core-profile-l1-1-0.dll │ │ api-ms-win-core-rtlsupport-l1-1-0.dll │ │ api-ms-win-core-string-l1-1-0.dll │ │ api-ms-win-core-synch-l1-1-0.dll │ │ api-ms-win-core-synch-l1-2-0.dll │ │ api-ms-win-core-sysinfo-l1-1-0.dll │ │ api-ms-win-core-timezone-l1-1-0.dll │ │ api-ms-win-core-util-l1-1-0.dll │ │ api-ms-win-crt-conio-l1-1-0.dll │ │ api-ms-win-crt-convert-l1-1-0.dll │ │ api-ms-win-crt-environment-l1-1-0.dll │ │ api-ms-win-crt-filesystem-l1-1-0.dll │ │ api-ms-win-crt-heap-l1-1-0.dll │ │ api-ms-win-crt-locale-l1-1-0.dll │ │ api-ms-win-crt-math-l1-1-0.dll │ │ api-ms-win-crt-process-l1-1-0.dll │ │ api-ms-win-crt-runtime-l1-1-0.dll │ │ api-ms-win-crt-stdio-l1-1-0.dll │ │ api-ms-win-crt-string-l1-1-0.dll │ │ api-ms-win-crt-time-l1-1-0.dll │ │ api-ms-win-crt-utility-l1-1-0.dll │ │ base_library.zip │ │ clr.pyd │ │ pyexpat.pyd │ │ Python.Runtime.dll │ │ python36.dll │ │ pywintypes36.dll │ │ select.pyd │ │ test_ble.exe │ │ ucrtbase.dll │ │ unicodedata.pyd │ │ VCRUNTIME140.dll │ │ win32wnet.pyd │ │ _asyncio.pyd │ │ _bz2.pyd │ │ _ctypes.pyd │ │ _decimal.pyd │ │ _hashlib.pyd │ │ _lzma.pyd │ │ _multiprocessing.pyd │ │ _overlapped.pyd │ │ _socket.pyd │ │ _ssl.pyd │ │ │ └─bleak │ └─backends │ └─dotnet │ BleakUWPBridge.dll │ └─__pycache__ ble.cpython-36.pyc bt_ctrl.cpython-36.pyc test_ble.cpython-36.pyc
最新发布
09-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值