Summer Training Team Selection (1) Problem F Line Them Up 判断升序降序
2016-04-30 22:20
561 查看
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 does
not 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.
2016 UESTC ACM Summer Training Team Selection (1)
ACM-ICPC 2015 Mid-Central Regional Problem F: Line Them Up
给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)
Thank you!
------from ProLights
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 does
not 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
相关文章推荐
- Summer Training Team Selection (1) Problem A ACM Contest Scoring 水题
- Title Four:Rainy
- TempDailyMonitor
- UVa 514 Rails
- MyBaits-快速入门
- Codeforces 667A Pouring Rain 667B Coat of Anticubism
- vc 6.0 中 error LNK2001: unresolved external symbol _main和fatal error LNK1120: 1 unresolved externals
- 免费邮件服务器:MailEnable
- LightOJ - 1236 Pairs Forming LCM 合数分解
- Codeforces Round #349 (Div. 2)-A. Pouring Rain(数学)
- ORA-01501: CREATE DATABASE failed
- Attended two wedding in the weekend
- Usage: gij [OPTION] ... CLASS [ARGS] ... to invoke CLASS.main, or
- HDU 1039 -Easier Done Than Said?
- 人工智能
- Light oj Trailing Zeroes (III) (二分查找)
- [LintCode] Paint House 粉刷房子
- [LintCode] Paint House II 粉刷房子之二
- Aizu 0121 Seven Puzzle
- 绘图室(PaintOffice)