马上要参加IEEE编程比赛了,找两道简单的题目练习一下。

首先贴上自己写的代码:

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
#include <stdlib.h>
#include <algorithm>int find_position(vector<char>& alpha, char target) {int nPosition=0;vector <char>::iterator iElement = find(alpha.begin(),alpha.end(),target);if (iElement != alpha.end()){nPosition = distance(alpha.begin(), iElement);}return nPosition;
}
void compare_string(string& a, int len_a, string& b, int len_b, vector<char>& alpha) {int length = len_a > len_b ? len_b:len_a;for (int i = 0; i < length; i++) {if (find_position(alpha,a[i]) > find_position(alpha,b[i])) {string temp = a;a = b;b = temp;return;}else if (find_position(alpha, a[i]) < find_position(alpha, b[i])) {return;}}if(len_a <= len_b){return;}else{string temp = a;a = b;b = temp;return;}
}int main(int argc, char* argv[])
{vector<char>alpha;string alpha_str;cin>>alpha_str;string temp=alpha_str;for(unsigned i=0;i<temp.size();i++){temp[i]-=32;}alpha_str+=temp;int N;cin>>N;for (unsigned i = 0; i < alpha_str.size(); i++) {alpha.push_back(alpha_str[i]);}vector<string>example(N);for (int i = 0; i < N; i++) {cin>> example[i];}for (unsigned  i = 0; i < example.size(); i++){for (unsigned  j = example.size() - 2; j >= i; j--) {compare_string(example[j], example[j].size(),example[j + 1], example[j+1].size(),alpha);if(j==0) break;}}for (unsigned  i = 0; i < example.size(); i++) {cout << example[i]<<endl;}return 0;
}

改来改去通过率也只有百分之七十,因为用的是冒泡排序,时间复杂度较高,有百分之三十的用例是超时的。在我修改的过程中一个叫Nickel的哥们用C++提交了一版感觉挺不错的,下面是他的代码:

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;map<char, int> m;bool compare(const string& s1, const string& s2){int len = s1.length() > s2.length() ? s2.length() : s1.length();for(int i=0; i<len; i++){char ch1 = s1[i];char ch2 = s2[i];if((islower(ch1) && islower(ch2)) || (isupper(ch1) && isupper(ch2))){if(m[tolower(ch1)] == m[tolower(ch2)]){continue;} else{return m[tolower(ch1)] < m[tolower(ch2)];}} else if(isupper(ch1)){return false;} else {return true;}}return s1.length() < s2.length();}int main() {string s;int N;cin >> s;cin >> N;for(int i=0; i<s.length(); i++){m[s[i]] = i;}vector<string> l(N);for(int i=0; i<N; i++){cin >> l[i];}sort(l.begin(), l.end(), compare);for(string s : l){cout << s << endl;}return 0;
}

对比感觉自己的思维方式,编程技巧和一些常用的函数都很欠缺。
这次比赛也不指望得奖,自己还是有自知之明的,只希望能够借这个机会长长见识,养成刷题和做记录的好习惯。

IEEE极限编程:Word Ordering相关推荐

  1. 2018 IEEE极限编程大赛 题解

    去年742,今年72,也算一种小小的进步. 明年前30(笑 1. Drawing Rooted Binary Trees 给定一个树的中序和前序的遍历,要求输出这棵树(包括空格的) 1 #includ ...

  2. IEEE论文Word 转 PDF文件的字体嵌入(embedded font)和pdf 文档去除链接

    word 2010 选择 文件-> 发布pdf 确认PDF是否字体都嵌入: pdf文件双击文件->属性->字体,查看是否都嵌入,如图: PDF文档删除链接: "高级---文 ...

  3. 第16届 IEEE 极限编程大赛 参赛记录

    第一次参赛,RK 333 和研究生学长学姐一起打的,可惜我太菜了,没能做出更多的题目 记录一下题目吧 题目链接 第一小时 我先签了最简单的题目 然后一起找规律 找了半个小时,才发现是字符串解密 而且偏 ...

  4. IEEE期刊论文格式(一)

    说明:主要是根据IEEE期刊模板而来. 如果是word文档,可以在IEEE的word模版上就行填入即可.不需要修改文章字体字号.如果是latex进行论文写作,也不能在latex中修改字体及字号等.如果 ...

  5. IEEE access的LaTeX 文档的使用技巧和教程

    IEEE access的LaTeX 文档的使用技巧和教程 LaTeX编译器 IEEE Access [word] & [Latex]模板 [Latex]插入图片 如何插入reference L ...

  6. Pandoc latex 转 word (docx)

    Pandoc,这是一个很棒的程序,可以在各种标记格式之间进行转换(包括markdown,latex和docx文档之间).更重要的是,Pandoc也是免费的开源软件. 第一步:安装 Pandoc的安装相 ...

  7. 计算机学院 图论方向,成电计算机学院本科生在计算机科学理论方向重要国际会议SAT上发表论文...

    近日,计算机科学与工程学院(网络空间安全学院)2017级本科生和肖鸣宇教授撰写的论文"A Fast Algorithm for SAT in Terms of Formula Length& ...

  8. Emojify - v2 吴恩达老师深度学习第五课第二周编程作业2

    吴恩达老师深度学习第五课第二周编程作业2,包含答案! Emojify! Welcome to the second assignment of Week 2. You are going to use ...

  9. 《Deep Learning With Python second edition》英文版读书笔记:第十一章DL for text: NLP、Transformer、Seq2Seq

    文章目录 第十一章:Deep learning for text 11.1 Natural language processing: The bird's eye view 11.2 Preparin ...

  10. 吴恩达深度学习5.2练习_Sequence Models_Emojify

    转载自吴恩达老师深度学习课程作业notebook Emojify! Welcome to the second assignment of Week 2. You are going to use w ...

最新文章

  1. 【linux】串口编程(二)——非阻塞接收
  2. div 自动换行_js自动打字--autotypejs
  3. java基础面试题整理-2021
  4. Android技术经理+资深工程师+研发工程师-杭州
  5. CSS设置超出表格的内容用省略号显示
  6. python百度手势识别_【百度大脑新品体验】手势识别
  7. 计算机网络【wireshark抓包分析】
  8. linux 桌面显示视频播放器,Ubuntu 13.10开启媒体播放器VLC桌面通知的步骤
  9. React Navigation 导航栏样式调整+底部角标消息提示
  10. 【sql:练习题3】查询在 SC 表存在成绩的学生信息
  11. xib加载的两种方式
  12. IIS7.5配制支持PHP脚本错误代码0x80070002
  13. iOS UI控件(2) UITextView
  14. vue3的语法使用总结api
  15. 中国游戏发展史V-02
  16. oracle 主键 外键
  17. go 获取文件的md5值
  18. linux单引号作用,单引号 双引号如何输入(Linux运维:单引号与双引号的使用)...
  19. PAT合集1096 大美数 (15 分)
  20. 记一次hydra密码破解神器的学习

热门文章

  1. 2-OAuth2腾讯微博开放平台API小试
  2. 基于麦克风阵列的语音信号处理技术
  3. r430服务器如何用u盘做系统,DELL R430服务器U盘安装操作系统指南.docx
  4. DynamipsGUI 2.8(CCNP模拟器)
  5. eclipse 使用教程
  6. 小米摄像头共享显示服务器错误6,小米摄像头
  7. linux 卸载nvidia显卡驱动,Ubuntu 16.04 卸载Nvidia显卡驱动和cuda
  8. BackgroundWorker使用总结
  9. discuz门户文章增加代码高亮
  10. 网络编程在线英英词典之查询模块(五)