hdu1718 Rank
2015-11-15 16:39
387 查看
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
int sco[105], ans, pri, a, b, i, j, N;
char st[1005][100], st0[100], cmp[100];
while(cin >> st0)
{
a = b = N = 0;
pri = 0;
while(~scanf("%s%d", &st[a], &sco[b]) && strcmp(st[a], "0") && sco[b] != 0)
{
a++;
b++;
N++;
}
for(i = 0; i < N; i++)
for(j = 0; j < N - i - 1; j++)
{
if(sco[j] > sco[j+1])
{
int t = sco[j];
sco[j] = sco[j+1];
sco[j+1] = t;
strcpy(cmp, st[j]);
strcpy(st[j], st[j + 1]);
strcpy(st[j + 1], cmp);
}
}
for(int k = 0; k < N; k++)
if(!strcmp(st[k], st0)) { ans = k; break; }
for(i = N - 1; i >= 0; i--)
{
if(sco[i] > sco[ans]) pri++;
else break;
}
printf("%d\n", pri + 1);
memset(sco, 0, sizeof(sco));
memset(st, 0, sizeof(st));
memset(st0, 0, sizeof(st0));
memset(cmp, 0, sizeof(cmp));
}
return 0;
}
心得:做完六级水到题,结果手好生。。。好歹a了。。。
#include <string.h>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
int sco[105], ans, pri, a, b, i, j, N;
char st[1005][100], st0[100], cmp[100];
while(cin >> st0)
{
a = b = N = 0;
pri = 0;
while(~scanf("%s%d", &st[a], &sco[b]) && strcmp(st[a], "0") && sco[b] != 0)
{
a++;
b++;
N++;
}
for(i = 0; i < N; i++)
for(j = 0; j < N - i - 1; j++)
{
if(sco[j] > sco[j+1])
{
int t = sco[j];
sco[j] = sco[j+1];
sco[j+1] = t;
strcpy(cmp, st[j]);
strcpy(st[j], st[j + 1]);
strcpy(st[j + 1], cmp);
}
}
for(int k = 0; k < N; k++)
if(!strcmp(st[k], st0)) { ans = k; break; }
for(i = N - 1; i >= 0; i--)
{
if(sco[i] > sco[ans]) pri++;
else break;
}
printf("%d\n", pri + 1);
memset(sco, 0, sizeof(sco));
memset(st, 0, sizeof(st));
memset(st0, 0, sizeof(st0));
memset(cmp, 0, sizeof(cmp));
}
return 0;
}
心得:做完六级水到题,结果手好生。。。好歹a了。。。
相关文章推荐
- 静态库 动态库 区别
- viewport 学习
- Struct对齐
- 各种Android大神的文章链接
- android studio和eclipse中获取sha1码
- 解密回文——栈
- Trie树|字典树的简介及实现(转)
- javascript延迟加载及异步(defer和async)
- javaScript-引用类型(三)
- OC学习心得之方法
- strcpy()、memcpy()、memmove()、memset()的实现
- 大数据下的日志-flume(一)简介及例子
- shell入门-tr替换字符和split切割大文件
- HDU 4548 树状数组
- gdb 调试中No symbol “***” in current context解决方法
- 系统组件:动作条ActionBar
- web服务端安全之权限漏洞
- HDOJ 3466 Proud Merchants 【0 1背包】
- java 重定向和转发的区别
- 二叉树的中序线索化以及遍历