Summer Training Team Selection (1) Problem F Line Them Up 判断升序降序
来源:互联网 发布:赛事专用软件源码php 编辑:程序博客网 时间:2024/05/21 14:49
Problem F
Line Them Up
Time limit: 1 second
An eccentric coach asks players on the team to line up alphabetically at the start of practice. The coach doesnot tell the players whether they need to line up in increasing or decreasing order, so they guess. If they
guess wrong, the coach makes them run laps before practice. Given a list of names, you are to determine if
the list is in increasing alphabetical order, decreasing alphabetical order or neither.
Input
The input consists of a single test case. The first line will contain the number N of people on the team
(2 N 20). Following that are N lines, each containing the name of one person. A name will be at least
two characters and at most 12 characters in length and will consist only of capital letters, and with no white
spaces (sorry BILLY BOB and MARY JOE). Duplicates names will not be allowed on a team.
Output
Output a single word: INCREASING if the list is in increasing alphabetical order, DECREASING if it is in
decreasing alphabetical order, and otherwise NEITHER.
Source
2016 UESTC ACM Summer Training Team Selection (1)
ACM-ICPC 2015 Mid-Central Regional Problem F: Line Them Up
My Solution
给n个字符串判断升序还是降序还是乱序
就定义一个, m = n;nn = n;
然后如果降了一次m--;
如果升了一次m++
最好用m和n比较
这个方法好像处理简单的字符串的时候挺常用的
if(2*nn == m+1) printf("INCREASING");
else if(m == 1) printf("DECREASING");
else printf("NEITHER");
复杂度 O(26*n)
#include <iostream>#include <cstdio>#include <cstring>using namespace std;char line1[16];char line2[16];int main(){ #ifdef LOCAL freopen("a.txt", "r", stdin); #endif // LOCAL int n, len1, len2,nn, m, t; scanf("%d", &n); m = n;nn = n; scanf("%s", line1);n--;len1 = strlen(line1); while(n--){ scanf("%s", line2); len2 = strlen(line2); t = m; int sz = len1 <= len2 ? len1 : len2; for(int i = 0; i < sz; i++){ if(line1[i] > line2[i]){ m--; break; } else if(line1[i] < line2[i]){ m++; break; } } if(t==m){ m += len1 <= len2 ? 1 : -1; } strcpy(line1, line2); len1 = len2; } //cout<<nn<<" "<<m<<endl; if(2*nn == m+1) printf("INCREASING"); else if(m == 1) printf("DECREASING"); else printf("NEITHER"); return 0;}
Thank you!
------from ProLights
0 0
- Summer Training Team Selection (1) Problem F Line Them Up 判断升序降序
- Summer Training Team Selection (1) Problem A ACM Contest Scoring 水题
- Summer Training Team Selection (1) Problem D Hidden Password STL,字符串匹配,简单题
- 2016 UESTC ACM Summer Training Team Selection (2)解题报告
- poj1112 Team Them Up!
- 1627 - Team them up!
- poj1112 Team Them Up!
- Team them up! UVA
- Team them up! UVA
- Team them up! UVA
- ecjtu-summer training #1 F (UVA 11461)
- Problem F. Flat----(2015 summer training #5)
- UESTC Summer Team Training #2
- line them up(判断字符串的升降)
- POJ 1112 Team Them Up
- [ZOJ1462][POJ1112] Team Them Up!
- poj 1112 Team Them Up!
- POJ 1112 Team Them Up!
- HTML5第9节课堂笔记(初探mui,制作手机归属地查询)
- HDU 5676 ztr loves lucky numbers(dfs+离线)——BestCoder Round #82(div.1 div.2)
- hdu 1039 Easier Done Than Said?
- 1.系统调用的过程
- Light OJ 1031 Easy Game 区间DP
- Summer Training Team Selection (1) Problem F Line Them Up 判断升序降序
- 学习PS基础
- Volley源码解析(一),基本概述
- 算法导论学习笔记(二)分治策略之最大子数组
- javascript中Object.create与new的不同
- OpenCV学习之安装
- 343. Integer Break
- 2.一个奇怪的fork程序
- iOS中实现获取文本内容的宽高