PAT-A 1071. Speech Patterns (25)

题目连接在此

题意
“单词”的定义为大小写字母、数字的组合。给出一行字符串,求出出现次数最多的单词及其出现次数(一切除了大小写字母、数字之外的字符都作为单词的分隔符)。字母不区分大小写,且最后结果输出小写形式。

思路
1. 用一个map<string,int>变量tbl存放每个单词出现的次数。
2. 在读入输入的字符串input后,对input进行枚举处理,如果是有效字符,则对应字符的出现次数+1;如果是无效字符,则跳过。
3. 最后对tbl进行遍历,找出出现次数最多的单词及出现次数。

#include<iostream>
#include<map>
#include<string>
#include<algorithm>

using namespace std;

map<string,int> tbl;

bool isWord(char c){
    if(c >= '0' && c <= '9') return true;
    if(c >= 'a' && c <= 'z') return true;
    if(c >= 'A' && c <= 'Z') return true;
    return false;
}

int main(){

    string input;
    getline(cin, input);

    string temp = "";
//  transform(input.begin(), input.end(),input.begin(), ::tolower); //将输入字符串全都转换成小写 

    input += " ";
    for(string::iterator it = input.begin(); it != input.end(); it++){
        if(isWord(*it)){  //如果是数字和字母 
            if(*it >= 'A' && *it <= 'Z'){   //如果为大侠字母 
                *it += 32;  //转换为小写字母 
            }
            temp += *it;   //将*it接上temp之后 
        } else{
            if(temp.length() != 0){  //如果temp不为空 
                tbl[temp]++;   //temp出现次数+1 
                temp.clear();  //置空temp 
            }
        }
    }

    int count = 0;
    string res = "";
    for(map<string, int>::iterator it = tbl.begin(); it != tbl.end(); it++){
        if(it->second > count){
            count = it->second;
            res = it->first;
        }
    }

    cout << res << " " << count;

    return 0;   
} 

注意点: 以上代码的在输入字符串input之后添加一个空格,是为了处理出现以有效字符结尾的字符串的情况,如以下两种:

    can
    can can
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz交叉编译qt4.8.7的流程: 1. 下载并解压gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz和qt-everywhere-opensource-src-4.8.7.tar.gz 2. 配置环境变量,将交叉编译工具链的路径添加到PATH中: ``` export PATH=/path/to/gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf/bin:$PATH ``` 3. 进入qt-everywhere-opensource-src-4.8.7目录,运行./configure命令,配置Qt的编译选项: ``` ./configure -embedded arm -xplatform qws/linux-arm-gnueabi-g++ -prefix /usr/local/qt4.8.7-arm -no-gfx-linuxfb -no-gfx-multiscreen -no-gfx-transformed -depths all -no-qt3support -no-scripttools -no-openssl -no-nis -no-cups -no-iconv -no-pch -no-dbus -no-phonon -no-opengl -no-javascript-jit -no-webkit -no-qml-debug -no-separate-debug-info -no-exceptions -no-accessibility -no-script -no-stl -no-xmlpatterns -no-multimedia -no-audio-backend -no-phonon-backend -no-webkit-qml-plugin -no-declarative -no-declarative-debug -no-gif -no-libtiff -no-mng -no-openssl -no-glib -no-pulseaudio -no-gstreamer -no-alsa -no-sm -no-xinerama -no-xkb -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-xshape -no-xinput -no-xkbcommon -no-xcb -no-xlib -no-kms -no-linuxfb -no-directfb -no-gfx-qvfb -no-largefile -no-nas-sound -no-webkitwidgets -no-javascriptcore -no-script -no-scripttools -no-xmlpatterns -no-svg -no-webkit -no-qml-debug -no-separate-debug-info -no-icu -no-openssl -no-sql-sqlite -no-sql-mysql -no-sql-odbc -no-sql-psql -no-sql-tds -no-tls ``` 参数说明: -embedded arm:选择Qt的嵌入式编译模式。 -xplatform qws/linux-arm-gnueabi-g++:指定交叉编译器和Qt平台的路径。 -prefix /usr/local/qt4.8.7-arm:指定Qt的安装路径。 其他参数是为了禁用不需要的模块和功能。 4. 运行make命令进行编译: ``` make ``` 5. 编译完成后,运行make install命令进行安装: ``` make install ``` 6. 将交叉编译后的Qt库拷贝到目标设备上,将头文件和库文件添加到交叉编译环境的搜索路径中。 7. 在交叉编译环境中使用qmake编译Qt应用程序: ``` /path/to/qt4.8.7-arm/bin/qmake make ``` 以上就是使用gcc-arm-10.2-2020.11-x86_64-aarch64-none-elf.tar.xz交叉编译qt4.8.7的流程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值