
水题
文章平均质量分 59
Matrix1254
爱代码,爱加班,爱咖啡可乐
爱挑战,爱钻研,爱打游戏
爱晚起,也爱工作到深夜。
我擅长技术,崇尚简单和懒惰
我神秘而孤僻,沉默而爱憎分明
我行我素,我是程序员
展开
-
pat1006 Sign In and Sign Out
很简单 直接AC #includeint main() { int n,i,sum = 0; int floor[105]; scanf("%d",&n); floor[0] = 0; for(i = 1; i <= n; i++) { scanf("%d",&floor[i]); if(floor[i] > floor[i-1]) {原创 2012-11-21 10:57:37 · 501 阅读 · 0 评论 -
pat 1042 Shuffling Machine
洗牌机,每次将牌洗到新的位置,输出洗K次后牌的顺序。简单,水题。在纸上写一下就清楚了,只是输出时要注意,S13,J1等。AC代码://1042 22:18#includeint a[60];int b[60];char c[5]="SHCD";int trans[60];int main(){ int k,i,j,num; //freopen("C:\\Document原创 2013-03-07 00:06:59 · 1098 阅读 · 0 评论 -
pat 1031 Hello World for U
简单摸拟题,找出最大的n1即可。AC代码:简单模拟 //1031 0:10-0:37#include#includeint main(){ int n1,n2; char str[100]; int i,j,k; scanf("%s",str); int len=strlen(str);/* n1=len/3;*/原创 2013-03-06 09:51:35 · 1157 阅读 · 0 评论 -
pat 1035 Password
估计是pat里最水的水题了,只要将对应的字母更换即可。AC代码://1035 15:50 - 16:16#include#includeconst int MAXN=1005;struct account{ char name[14]; char pass[14]; int mod;}a[MAXN];int main(){ int n,i原创 2013-03-06 16:12:02 · 902 阅读 · 0 评论 -
pat 1040 Longest Symmetric String
题意要求最长回文串,遍历一遍,找到回文串最中间的那个字母(BAB中的A或ABBA中的第一个B),再以该字母为中心,往左右拓展,若能相等,则相加。就算样例可以过,也要测试一下其它简单的情况,如AAA, BB。要注意的数据点有:aaa 3 aassaa 6 AC代码://1040 21:20#include#includechar str[1005];原创 2013-03-06 21:51:23 · 896 阅读 · 0 评论 -
1048 Find Coins
终于拿下了一题,其实很简单,输入时就将b[a[i]]标记为1, 若发现有b[m-a[i]]为1,取其最小值。AC代码: //1048 19:48-20:02#includeconst int NUM=100005;int a[NUM];int b[NUM];int main(){ int n,i,m; int temp,min=NUM; //freo原创 2013-03-07 19:58:55 · 990 阅读 · 0 评论 -
pat 1007 Maximum Subsequence Sum
题目很简单,就是求最大连续子串和,和对应的元素。我看成求对应的元素下标,WA了N多次,太无语了。要认真看输入和输出要求啊。一次遍历即可(有一个小点未过,不知为何)。若用两次遍历,纯暴力,就全过了。AC代码:#includeusing namespace std;const int NUM=10005;const int INF=-10000000;int a[NUM],su原创 2013-02-26 23:41:15 · 784 阅读 · 0 评论 -
pat 1025 PAT Ranking
简单题,只是一开始用vector rank[NUM]用得不太熟,巩固了一下sort的compare函数写法。得抓紧时间做题了,以后博客先略写,有空再来补充。#include#include#include#includeusing namespace std;struct student{ string id; int score; int loc_id; int原创 2013-03-02 20:34:08 · 470 阅读 · 0 评论 -
pat 1027 Colors in Mars
简单题 进制转化 //1027 20:40#include#includeusing namespace std;char ra[15]="0123456789ABC";vector a[3];void tenToNum(int order,int x){ int i=0,j; if(x==0) a[order].push_back(0); e原创 2013-03-02 21:12:33 · 504 阅读 · 0 评论 -
pat 1030 Travel Plan
虽然是30分题,其实是简单题,只怪自己不清晰,想到什么dijskra和bellmanford的去了,浪费了不少时间。后来直接用DFS解决。//1030 23:00#includeconst int NUM=505;const int INF=0x7fffffff;int map[NUM][NUM],cost[NUM][NUM];int visit[NUM];in原创 2013-03-03 01:32:18 · 706 阅读 · 0 评论 -
LeetCode-Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()原创 2014-03-29 09:53:48 · 718 阅读 · 0 评论 -
LeetCode-Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus points for you原创 2014-03-22 08:20:37 · 689 阅读 · 0 评论 -
LeetCode-Implement strStr()
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.[Code]class Solution {public: char *strStr(char *haystack原创 2014-03-22 08:13:03 · 711 阅读 · 0 评论 -
LeetCode-Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2014-03-22 07:30:46 · 780 阅读 · 0 评论 -
pat 1041 Be Unique
太简单的水题了,直接标记即可。AC代码:#includeint a[100005];int c[100005]={0};int main(){ int n; //freopen("C:\\Documents and Settings\\Administrator\\桌面\\input.txt","r",stdin); scanf("%d",&n); in原创 2013-03-06 22:04:59 · 1144 阅读 · 1 评论 -
pat 1039 Course List for Student(23分)
简单题,定义一个map >即可。将对应学生的选课进行排序,但最后一点总是超时,换成scanf和printf,还是超。以后再看吧。代码://1039 20:28-21:12#include#include#include#include#includeusing namespace std;map > m;int main(){ int n,i,k原创 2013-03-06 21:02:45 · 1008 阅读 · 0 评论 -
pat 1001
简单水题#include#define NUM 15int cnt[NUM];int main(){ int a,b,sum; scanf("%d %d",&a,&b); sum=a+b; if(sum==0){ printf("0"); return 0; } if(sum<0){ printf("-"); sum=0-sum;原创 2013-02-14 18:15:32 · 462 阅读 · 0 评论 -
pat 1019
简单水题#include#define NUM 1002int ans[NUM];int flag;void reverse(int n, int radix){ int index=0,i,j; while(n){ ans[index++]=n%radix; n/=radix; } index--; for(i=0,j=index;i<=(原创 2013-02-14 22:18:06 · 501 阅读 · 0 评论 -
pat 1011
简单水题#includeint main(){ double odd,w,t,l; odd=0.65; freopen("C:\\Documents and Settings\\Administrator\\桌面\\input.txt","r",stdin); for(int i=0;i<3;i++){ scanf("%lf%lf%lf",&w,&t,&l原创 2013-02-14 18:20:18 · 435 阅读 · 0 评论 -
pat 1015
简单水题#include#includeint ans[105];int transfer(int n, int radix){ int index=0,res=0; while(n){ ans[index++]=n%radix; n/=radix; } for(int i=0;i<index;i++){ res*=radix; res+原创 2013-02-14 20:58:53 · 525 阅读 · 0 评论 -
pat 1002 A+B for Polynomials
简单的多项式相加。用两个数组分别保存,找出最大的下标,逐项相加。#includeusing namespace std;const int num=1005;double a[num],b[num];int main(){ int n,i,index,m; double val; int alen=-1,blen=-1,count=0; scanf("%d",&n); wh原创 2013-02-18 12:10:00 · 1007 阅读 · 1 评论 -
pat 1012 The Best Rank
代码极其冗余,有重复时注意排名顺序。 1 2 3 3 5 不是 1 2 3 3 4 。。。。。AC代码:#include#include#includeusing namespace std;#define NUM 2005struct Student{ char str[9]; int c; int m; int e; int a;原创 2013-02-19 00:22:43 · 715 阅读 · 0 评论 -
pat 1009 Product of Polynomials
简单的多项式相乘。#includeusing namespace std;const int iMax=5005;double a[iMax]={0},b[iMax]={0},c[iMax]={0};int main(){ int n,m,i,j,alen,blen,index,count; double val; //freopen("C:\\Document原创 2013-02-18 18:19:49 · 1023 阅读 · 0 评论 -
pat 1010 radix 部分正确20分
将两个其它进制的数都转化为10进制,再对比两者是否相等即可。题目没说范围,据说会出到这样的数据:1234567890 10 1 10 ,于是必须使用二分来做,否则必然TLE。部分正确代码:#include#includechar a[12],b[12];#define NUM 1000int dis(char a){ if(a>='0'&&a<='9') re原创 2013-02-18 21:12:00 · 1410 阅读 · 0 评论 -
pat 1032 Sharing
找两条链表的公共结点,先遍历其中一条,并且一一做访问标记,再遍历第二条,一旦访问过就输出结点值。结点值一开始一直用string来保存,用了map,太麻烦,最后一点超时了。参考网上程序,改用int型来保存,顺利ac。有时需要的是思路的转换。 #includeconst int NUM=100005;int a[NUM];int visit[NUM];int main(){原创 2013-03-05 20:14:25 · 1354 阅读 · 0 评论 -
pat 1029 Median
两个数列求中位数,简单排序取中位数,却超时了3组,以后再看。后仔细看题目发现,两个数列已是排好序了的,改用合并排序,过了。我的程序跟别人的一模一样,却有两点没过。//1029 22:00#include#includeconst int NUM=10000005;long a[NUM],b[NUM];int cmp(const void *a, const void *b)原创 2013-03-02 22:54:07 · 685 阅读 · 0 评论 -
pat 1028 List Sorting
简单排序题,最后一个点估计是输入超时,以后再改。最后一个改成用scanf和printf后就过了。另外,sort的仿函数返回值要用bool,不要用int,不然会出现意想不到的情况。 //21:20#include#include#include#includeusing namespace std;const int NUM=100005;struct stude原创 2013-03-02 21:50:49 · 574 阅读 · 0 评论 -
pat 1036 Boys vs Girls
太简单了,就不说了,将男生组和女生组排序,取女生组最高分和男生组最低分。AC代码://1036 16:16 - 16:44#include#includeusing namespace std;const int MAXN=1005;struct student{ char name[14]; char gender; char sid[14]; i原创 2013-03-06 16:40:46 · 779 阅读 · 0 评论 -
pat 1037 Magic Coupon
简单题,先将两数列从小到大排序,再遍历个数少的数列,使得短数列:[----] [++++]对 应:| | | |长数列:[---------][++++++++]负数与长数列的头部相乘,正数与长数列的尾部相乘。AC代码://1037 17:57-18:59#include#include原创 2013-03-06 19:04:57 · 1128 阅读 · 0 评论 -
LeetCode-Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2014-03-22 06:27:35 · 594 阅读 · 0 评论