HDU1225 字符串
水题~~
字符串的处理+排序
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 const int maxn = 5005; 6 struct node{ 7 char name[ 105 ]; 8 int win,lost,diff,score; 9 }team[ maxn ]; 10 int cnt; 11 void init( int n ){ 12 for( int i=0;i<=n;i++ ){ 13 team[ i ].win=team[ i ].lost=team[ i ].diff=team[ i ].score=0; 14 //memset( team[i].name,'\0',sizeof( team[i].name )); 15 } 16 cnt=0; 17 } 18 int find( char tt[] ){ 19 if( cnt==0 ){ 20 strcpy( team[0].name,tt ); 21 cnt++; 22 return 0; 23 } 24 int i; 25 for( i=0;i<cnt;i++ ){ 26 if( strcmp( tt,team[i].name )==0 ){ 27 return i; 28 } 29 } 30 if( i==cnt ){ 31 strcpy( team[cnt].name,tt ); 32 cnt++; 33 return cnt-1; 34 } 35 } 36 bool cmp( node a,node b ){ 37 if( a.score!=b.score ) 38 return a.score>b.score; 39 else if( a.diff!=b.diff ) 40 return a.diff>b.diff; 41 else if( a.win!=b.win ) 42 return a.win>b.win; 43 else if( strcmp( a.name,b.name )>0 ) 44 return false; 45 else return true; 46 } 47 int main(){ 48 int n; 49 while( scanf("%d",&n)!=EOF ){ 50 init( n ); 51 char n1[ 105 ],n2[ 105 ]; 52 int num1,num2; 53 for( int i=0;i<(n*(n-1));i++ ){ 54 scanf("%s VS %s %d:%d",n1,n2,&num1,&num2); 55 int f1=find( n1 ); 56 int f2=find( n2 ); 57 if( num1==num2 ){ 58 team[ f1 ].score++; 59 team[ f2 ].score++; 60 team[ f1 ].win+=num1; 61 team[ f1 ].lost+=num1; 62 team[ f2 ].win+=num2; 63 team[ f2 ].lost+=num2; 64 } 65 else if( num1>num2 ){ 66 team[ f1 ].win+=num1; 67 team[ f1 ].lost+=num2; 68 team[ f2 ].win+=num2; 69 team[ f2 ].lost+=num1; 70 team[ f1 ].score+=3; 71 } 72 else if( num1<num2 ){ 73 team[ f1 ].win+=num1; 74 team[ f1 ].lost+=num2; 75 team[ f2 ].win+=num2; 76 team[ f2 ].lost+=num1; 77 team[ f2 ].score+=3; 78 } 79 } 80 for( int i=0;i<n;i++ ){ 81 team[ i ].diff=team[ i ].win-team[ i ].lost; 82 } 83 sort( team,team+n,cmp ); 84 for( int i=0;i<n;i++ ){ 85 printf("%s %d\n",team[i].name,team[i].score); 86 } 87 printf("\n"); 88 } 89 return 0; 90 }
转载于:https://www.cnblogs.com/xxx0624/archive/2013/02/27/2935684.html
HDU1225 字符串相关推荐
- Redis 笔记(11)— 文本协议 RESP(单行、多行字符串、整数、错误、数组、空值、空串格式、telnet 登录 redis)
RESP 是 Redis 序列化协议Redis Serialization Protocol 的简写.它是一种直观的文本协议,优势在于实现异常简单,解析性能极好. Redis 协议将传输的结构数据 ...
- Go 知识点(16)— 将枚举值转换为字符串
package mainimport "fmt"// 将 int 声明 为 ChipType 芯片类型. type ChipType intconst (None ChipType ...
- HJ75 公共字符串计算
描述 给定两个只包含小写字母的字符串,计算两个字符串的最大公共子串的长度. 注:子串的定义指一个字符串删掉其部分前缀和后缀(也可以不删)后形成的字符串. 输入描述: 输入两个只包含小写字母的字符串 输 ...
- C++ 笔记(36)— 接收输入字符串的几种方法
C++中常见的几种输入字符串的方法如下: std::cin.std::cin.get().std::cin.getline().std::getline().std::gets().std::getc ...
- 算法基础(09)— 字符串常用操作
1. 字符串定义 字符串 string 是由 n 个字符组成的一个有序整体 n >= 0.例如,s = "BEIJING" ,s 代表这个串的串名,BEIJING 是串的值. ...
- C++ 笔记(35)— std::to_string 转换整形数字为字符串
1. 函数原型 string to_string (int val); string to_string (long val); string to_string (long long val); s ...
- Linux shell 学习笔记(8)— 使用结构化命令(if-then 语句、数值比较、字符串比较、文件比较、case 语句)
1. 使用 if-then 语句 最基本的结构化命令就是if-then语句.if-then语句有如下格式. if command then commands fi 或者 if command; t ...
- Python 将字符串转为字典
引言 在工作中遇到一个小问题,需要将一个 Python 的字符串转为字典,比如字符串: user_info = '{"name" : "john", " ...
- leetcode 5. Longest Palindromic Substring 字符串中的最长回文数 逐步从O(n^2)优化至线性时间
题目 解析 思路一 暴力解法 思路二 指针+最大长度 思路3 由中间至两边找回数 思路4 Manacher's algorithm 线性时间 参考文档 题目 链接 给定一个字符串 s,找到 s 中最长 ...
最新文章
- 2022-2028年中国文化旅游业投资分析及前景预测报告(上中下卷)
- 通过分析 JDK 源代码研究 TreeMap 红黑树算法实现--转
- postfix导致maillog填满磁盘空间的巨坑!
- RHEL5.8安装Oracle10g
- lua面向对象编程之点号与冒号的差异详细比较
- 公有云网络服务需要考虑的关键点
- PHP正则表达式的运用
- Bolt XML和JQBolt Lua代码自动补全插件配置教程
- FastAPI + Vue 前后端分离 接口自动化测试工具 apiAutoTestWeb
- logging 日志表的设计
- Java 分布式框架面试题合集
- 什么是servlet技术?如何部署和新建一个servlet?
- JS 获得FileUpload1 的完整路径
- 手游联运系统后台有什么功能?后台功能大全!
- ERP系统BOM详细解析
- 深入理解Object.entries()
- 3月27日下午上完毛概后是一节体育课,这学期要考篮球和跳绳
- win10系统 纯净版 安装
- Abaqus 实体平移和旋转
- 吴恩达深度学习coursework1
热门文章
- CLIP-ViL:CLIP对视觉和语言任务有多大的好处?UC BerkeleyUCLA团队给出了答案!
- ICCV 2019 Oral 端到端任意形状场景文字识别
- MySQL事件与定时器,mysql下存储过程与定时器
- 腾讯2021春季校园招聘启动
- python处理mat数据_python读取.mat文件的数据及实例代码
- Python3 Ocr 初探
- Mysql配置文件读取顺序
- php 函数 中文,PHP语言之PHP中文函数连载(二)
- mac在命令行里获取root权限
- list元素求和_LeetCode刷题实战82:删除排序链表中的重复元素 II