杭电2629 Identity Card
题目意思很简单,就是根据身份证号码来确定一个人的籍贯和生日,(然而我开始脑子抽了还以为还要根据奇数偶数判断男女233333)。
然后我的暴力ac代码:
#include <iostream>
#include<math.h>
#include <iomanip>
#include<cstdio>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std; int main()
{
int n;
string id;
cin>>n; while(n--){
cin>>id;
if(id[]==''&&id[]==''){
cout<<"He/She is from Zhejiang,and his/her birthday is on "<<id[]<<id[]<<","<<id[]<<id[]<<","<<id[]<<id[]<<id[]<<id[]<<" based on the table."<<endl;
} else if(id[]==''&&id[]==''){
cout<<"He/She is from Beijing,and his/her birthday is on "<<id[]<<id[]<<","<<id[]<<id[]<<","<<id[]<<id[]<<id[]<<id[]<<" based on the table."<<endl;
} else if(id[]==''&&id[]==''){
cout<<"He/She is from Taiwan,and his/her birthday is on "<<id[]<<id[]<<","<<id[]<<id[]<<","<<id[]<<id[]<<id[]<<id[]<<" based on the table."<<endl;
} else if(id[]==''&&id[]==''){
cout<<"He/She is from Hong Kong,and his/her birthday is on "<<id[]<<id[]<<","<<id[]<<id[]<<","<<id[]<<id[]<<id[]<<id[]<<" based on the table."<<endl;
} else if(id[]==''&&id[]==''){
cout<<"He/She is from Macao,and his/her birthday is on "<<id[]<<id[]<<","<<id[]<<id[]<<","<<id[]<<id[]<<id[]<<id[]<<" based on the table."<<endl;
} else if(id[]==''&&id[]==''){
cout<<"He/She is from Tibet,and his/her birthday is on "<<id[]<<id[]<<","<<id[]<<id[]<<","<<id[]<<id[]<<id[]<<id[]<<" based on the table."<<endl;
} else if(id[]==''&&id[]==''){
cout<<"He/She is from Liaoning,and his/her birthday is on "<<id[]<<id[]<<","<<id[]<<id[]<<","<<id[]<<id[]<<id[]<<id[]<<" based on the table."<<endl;
} else {
cout<<"He/She is from Shanghai,and his/her birthday is on "<<id[]<<id[]<<","<<id[]<<id[]<<","<<id[]<<id[]<<id[]<<id[]<<" based on the table."<<endl;
} }
return ;
}
想表示下,我开始并没有顺利ac因为,我最后一行的输出多了一个空格,233333.
然后就去看了下别人的代码,于是想补充下字符串的一些知识:
一个截取字符串的函数substr(),觉得比较方便,该函数的用法见下面一个示例代码,一看便知:
#include<string>
#include<iostream>
using namespace std;
main()
{
string s("12345asdf");
string a=s.substr(,); //获得字符串s中 从第0位开始的长度为4的字符串
cout<<a<<endl;
}
ac代码:
#include <iostream>
#include<string> using namespace std; int main(void)
{
int n;
string input_str,place;
cin>>n;
for(int i=; i<n; i++)
{
cin>>input_str;
if(input_str.substr(,)=="")
place="Zhejiang";
else if(input_str.substr(,)=="")
place="Beijing";
else if(input_str.substr(,)=="")
place="Taiwan";
else if(input_str.substr(,)=="")
place="Hong Kong";
else if(input_str.substr(,)=="")
place="Macao";
else if(input_str.substr(,)=="")
place="Tibet";
else if(input_str.substr(,)=="")
place="Liaoning";
else if(input_str.substr(,)=="")
place="Shanghai"; cout <<"He/She is from"<<" "<< place
<< ",and his/her birthday is on"<<" "<<input_str.substr(,)<<","
<<input_str.substr(,)<<","<<input_str.substr(,)<<" "
<<"based on the table."<<endl;
} return ;
}
补充部分来自:http://blog.csdn.net/always2015/article/details/45391791
杭电2629 Identity Card的更多相关文章
- hdu 2629 Identity Card (字符串解析模拟题)
这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 2629 Identity Card
简单题 给出身份证号 判断住址 和出生年月 熟练字符串的操作 主要是string::substr(s, l)//s:起始位置 l长度 #include <iostream> #includ ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 杭电acm阶段之理工大版
想參加全国软件设计大赛C/C++语言组的同学,假设前一篇<C和指针课后练习题总结>没看完的,请先看完而且依照上面的训练做完,然后做以下的训练. 传送门:http://blog.csdn.n ...
- acm入门 杭电1001题 有关溢出的考虑
最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...
- 杭电acm 1002 大数模板(一)
从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...
- 杭电OJ——1198 Farm Irrigation (并查集)
畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
- C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~
暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...
随机推荐
- js动态创建的select2标签样式加载不上解决办法
js动态创建的select2标签样式加载不上:调用select2的select2()函数来初始化一下: js抛出了Uncaught query function not defined for Sel ...
- 每天进步一点点------Allegro中SYMBOL种类
Allegro 中SYMBOL 种类在Allegro 中, Symbol 有五种, 它们分别是Package Symbol .Mechanical Symbol.Format Symbol.Shape ...
- 每天进步一点点------SOPC的uC/OS-II应用(一)
uC/OS-II(又名Micro C/OS)是基于嵌入式系统的完整的,可移植.可固化.可裁剪的可剥夺型实时内核,其已经广泛应用在航空飞行器.医疗设备.工业控制等可靠性和稳定性要求较高的场合.该内核的代 ...
- vue基础api
vue比jq好处 1jq 频繁操作dom 增加了性能消耗 vue 模拟dom 从内存中拿 2jq 数据没有统一管理 vue 统一管理数据 3vue 组件开发可以提取出公共的html或js mv*好 ...
- PMP概略学习下--主体内容
4 知识主体 4.1 主要知识简介 PMP所有的知识围绕五大过程组和十大知识领域展开.五大过程组包括启动.规划.执行.监控.结尾.启动的内容主要是定义项目或阶段.获得授权以及正式开始:规划的内容主要 ...
- 如何将mongo查询结果导出到文件中
1.新建一个js文件,将查询方法写进去,如dump.js,文件内容如下 var c = db.campaign.find({status:1}).limit(5) while(c.hasNext()) ...
- 如何开通linux机器的对外访问端口
1.先查看是否已经开通 2.没有开通,去linux机器查看防火墙,确实没有开通 3.修改防火墙 vim /etc/sysconfig/iptables 4.重启防火墙之后重新查看已经可以看到8000端 ...
- The Reason Why Cosmetic Airless Bottles Are Widely Used
The contents of the Cosmetic Airless Bottles can be isolated from the air, to prevent the product ...
- unittest框架,漂亮的报告BeautifulReport配置与错误截图详细解说
1.下载BeautifulReport模块 下载地址:https://github.com/TesterlifeRaymond/BeautifulReport 2.解压与存放路径 下载Beautifu ...
- git 本地回滚与远程库回滚
不说废话,开始: 一.本地回滚: git reset --hard commit-id //回滚到commit-id 二.远程回滚操作分3步:①将本地分支退回到某个commit ②删除远程分支 ...