2018-5-18 HDU 做题记录

2081 手机短号

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 36379    Accepted Submission(s): 22104


Problem Description
大家都知道,手机号是一个11位长的数字串,同时,作为学生,还可以申请加入校园网,如果加入成功,你将另外拥有一个短号。假设所有的短号都是是 6+手机号的后5位,比如号码为13512345678的手机,对应的短号就是645678。
现在,如果给你一个11位长的手机号码,你能找出对应的短号吗?
 

Input
输入数据的第一行是一个N(N <= 200),表示有N个数据,接下来的N行每一行为一个11位的手机号码。
 

Output
输出应包括N行,每行包括一个对应的短号,输出应与输入的顺序一致。
 

Sample Input
 
 
2 13512345678 13787654321
 

Sample Output
 
 
645678 654321
 
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	char s[20];
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("\n");//把题目数据中输入的换行符吃掉,否则结果不对!
	    for(int j=0;j<11;++j)
	    {
	    	scanf("%c",&s[j]);
		}
		printf("6");
		for(int j=6;j<11;++j)
		  printf("%c",s[j]);
		printf("\n"); 
	}
	return 0;
 } 

2093 考试排名

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17730    Accepted Submission(s): 6141


Problem Description
C++编程考试使用的实时提交系统,具有即时获得成绩排名的特点。它的功能是怎么实现的呢?
我们做好了题目的解答,提交之后,要么“AC”,要么错误,不管怎样错法,总是给你记上一笔,表明你曾经有过一次错误提交,因而当你一旦提交该题“AC”后,就要与你算一算帐了,总共该题错误提交了几回。虽然你在题数上,大步地跃上了一个台阶,但是在耗时上要摊上你共花去的时间。特别是,曾经有过的错误提交,每次都要摊上一定的单位时间分。这样一来,你在做出的题数上,可能领先别人很多,但是,在做出同样题数的人群中,你可能会在耗时上处于排名的劣势。
例如:某次考试一共8题(A,B,C,D,E,F,G,H),每个人做的题都在对应的题号下有个数量标记,负数表示该学生在该题上有过的错误提交次数,但到现在还没有AC,正数表示AC所耗的时间,如果正数a跟上一对括号,里面有个整数b,那就表示该学生提交该题AC了,耗去了时间a,同时,曾经错误提交了b次,因此对于下述输入数据:



若每次错误提交的罚分为20分,则其排名从高到低应该是这样的:
Josephus 5 376
John 4 284
Alice 4 352
Smith 3 167
Bob 2 325
Bush 0 0
 

Input
输入数据的第一行是考试题数n(1≤n≤12)以及单位罚分数m(10≤m≤20),每行数据描述一个学生的用户名(不多于10个字符的字串)以及对所有n道题的答题现状,其描述采用问题描述中的数量标记的格式,见上面的表格,提交次数总是小于100,AC所耗时间总是小于1000。

 

Output
将这些学生的考试现状,输出一个实时排名。实时排名显然先按AC题数的多少排,多的在前,再按时间分的多少排,少的在前,如果凑巧前两者都相等,则按名字的字典序排,小的在前。每个学生占一行,输出名字(10个字符宽),做出的题数(2个字符宽,右对齐)和时间分(4个字符宽,右对齐)。名字、题数和时间分相互之间有一个空格。
 

Sample Input
 
  
8 20 Smith -1 -16 8 0 0 120 39 0 John 116 -2 11 0 0 82 55(1) 0 Josephus 72(3) 126 10 -3 0 47 21(2) -2 Bush 0 -1 -8 0 0 0 0 0 Alice -2 67(2) 13 -1 0 133 79(1) -1 Bob 0 0 57(5) 0 0 168 -7 0
 

Sample Output
 
  
Josephus 5 376 John 4 284 Alice 4 352 Smith 3 167 Bob 2 325 Bush 0 0
 
//通过这个题目,复习了不少之前的东西。 
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=10005;
struct STU{
	char name[15];
	int tms,score;
}stu[N];
bool cmp(STU A,STU B)//结构体排序,STU A  
{
	if(A.tms!=B.tms) return A.tms>B.tms;
	else if(A.score!=B.score) return A.score<B.score;
	return strcmp(A.name,B.name)<0;
}
void pout(int t)
{
	for(int i=0;i<t;++i)
	{
		printf("%-10s %2d %4d\n",stu[i].name,stu[i].tms,stu[i].score);
		//输出,注意-10左对齐,10右对齐 
	}
}
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int t=0;
		while(scanf("%s",stu[t].name)!=EOF)// scanf("%s",stu[t].name),其中name为char数组类型,前面没有& 
		{
			stu[t].score=0;
			stu[t].tms=0;
			char ch[10];
			for(int i=1;i<=n;++i)
			{
				scanf("%s",ch);
				if(ch[0]=='-') continue;
				if(strcmp(ch,"0")==0) continue;//strcmp(char[],char[]) 比较char[]类型,相同为0,前面小<0 
				stu[t].tms++;
				int j=0,tmp=0;
				for(j=0;j<strlen(ch);++j)//strlen(A) char A[],求A的长度 
				{
					if(ch[j]=='(') break;
					tmp=tmp*10+ch[j]-'0';
				}
				stu[t].score+=tmp;
				j++;
				tmp=0;
				for(;j<strlen(ch)-1;++j)
				{
					tmp=tmp*10+ch[j]-'0';
				}
				stu[t].score+=tmp*m;
			}
			t++;
		}
		sort(stu,stu+t,cmp);
		pout(t);
	}
	return 0;
}

1004 Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 141127    Accepted Submission(s): 55777


Problem Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.

This year, they decide to leave this lovely job to you.
 

Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.
 

Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
 

Sample Input
 
   
5 green red blue red red 3 pink orange pink 0
 

Sample Output
 
   
red pink
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
struct Node{
	char name[20];
	int cnt;
};
int n;
bool cmp(Node A,Node B)
{
	return A.cnt>B.cnt;
}
int main()
{
	bool fff=false;
	while(scanf("%d",&n)!=EOF)
	{
		Node node[1005]={0};//想让每次输入n时,node都是全新的?每次重新定义,然后加以一个={0} 
		if(n==0) break;
		int t=0;
		char ch[20];
		for(int i=0;i<n;++i)
		{
			scanf("%s",ch);
			bool flag=false;
			for(int j=0;j<t;++j)
			{
				if(strcmp(ch,node[j].name)==0)
				{
					node[j].cnt++;
					flag=true;
					break;
				}
			}
			if(!flag)
			{
				t++;
				node[t].cnt=0;
				for(int p=0;p<strlen(ch);++p)
				{
					node[t].name[p]=ch[p];
				}
				node[t].cnt++;
			}
		 }
		sort(node,node+t+1,cmp);
		printf("%s\n",node[0].name);
		
	}
	return 0;
}

2057 A + B Again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 34518    Accepted Submission(s): 13993


Problem Description
There must be many A + B problems in our HDOJ , now a new one is coming.
Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too.
Easy ? AC it !
 

Input
The input contains several test cases, please process to the end of the file.
Each case consists of two hexadecimal integers A and B in a line seperated by a blank.
The length of A and B is less than 15.
 

Output
For each test case,print the sum of A and B in hexadecimal in one line.
 

Sample Input
 
  
+A -A +1A 12 1A -9 -1A -12 1A -AA
 

Sample Output
 
  
0 2C 11 -2C -90
/* HDU2057 A + B Again */  
  
#include <stdio.h>  
  
int main(void)  
{  //%ll表示长整形,x表示16进制, 
    long long a, b, result;  
  
    while(scanf("%llx %llx", &a, &b) != EOF) {  
        result = a + b;  
  
        if (result >= 0)  
            printf("%llX\n", result);  
        else  
            printf("-%llX\n", -result);  
    }  
  
    return 0;  
}  
/* HDU2057 A + B Again */  
  
#include <stdio.h>  
  
int main(void)  
{  
    __int64 a, b, result;  
  //_int64 I64也表示长整形
    while(scanf("%I64X %I64X", &a, &b) != EOF) {  
        result = a + b;  
  
        if (result >= 0)  
            printf("%I64X\n", result);  
        else  
            printf("-%I64X\n", -result);  
    }  
  
    return 0;  
}  





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值