题目意思很简单,就是根据身份证号码来确定一个人的籍贯和生日,(然而我开始脑子抽了还以为还要根据奇数偶数判断男女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的更多相关文章

  1. hdu 2629 Identity Card (字符串解析模拟题)

    这题是一个字符串模拟水题,给12级学弟学妹们找找自信的,嘿嘿; 题目意思就是要你讲身份证的上的省份和生日解析出来输出就可以了: http://acm.hdu.edu.cn/showproblem.ph ...

  2. HDU 2629 Identity Card

    简单题 给出身份证号 判断住址 和出生年月 熟练字符串的操作 主要是string::substr(s, l)//s:起始位置 l长度 #include <iostream> #includ ...

  3. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  4. 杭电acm阶段之理工大版

    想參加全国软件设计大赛C/C++语言组的同学,假设前一篇<C和指针课后练习题总结>没看完的,请先看完而且依照上面的训练做完,然后做以下的训练. 传送门:http://blog.csdn.n ...

  5. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  6. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  7. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  8. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  9. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

随机推荐

  1. Linux中通配符

    通配符是由shell处理的, 它只会出现在 命令的“参数”里.当shell在“参数”中遇到了通配符时,shell会将其当作路径或文件名去在磁盘上搜寻可能的匹配:若符合要求的匹配存在,则进行代换(路径扩 ...

  2. mysql5.7导出数据提示--secure-file-priv选项问题的解决方法

    mysql可使用 into outfile 参数把表中数据导出到csv,例如可用以下命令把user表的数据导出到user.csv select * from user into outfile '/t ...

  3. 浅谈Power Signoff

    Power Analysis是芯片设计实现中极重要的一环,因为它直接关系到芯片的性能和可靠性.Power Analysis 需要Timing Analysis 产生包含频率.transition 等时 ...

  4. codeforces C. Primes and Multiplication(快速幂 唯一分解定理)

    题目链接:http://codeforces.com/contest/1228/problem/C 题解:给定一个函数f,g,题目有描述其中的表达式含义和两者之间的关系. 然后计算: 首先把给定的x用 ...

  5. ThinkPhp5 中Volist标签的用法

    Volist标签一般是和内置方法assign()搭配使用,将值从后台传到前台,是当下比较流行的一种传值方法 本文实例讲述了ThinkPHP模板循环输出Volist标签用法.分享给大家供大家参考,具体如 ...

  6. 1.2 Jmeter 使用代理录制脚本

    参考文档: http://jingyan.baidu.com/article/4e5b3e19333ff191911e2459.html 利用JMeter配置代理:1.添加线程组:  Test Pla ...

  7. Ansible - 模块 - shell

    概述 ansible 的 shell 模块 准别 ansible 控制节点 ansible 2.8.1 远程节点 OS CentOS 7.5 无密码登录 已经打通 1. 模块 概述 ansible 功 ...

  8. python的datetime库

    datetime 库 简介 获取时间 主要提供程序计时器 基本使用

  9. 基于selenium+Python3.7+yaml+Robot Framework的UI自动化测试框架

    前端自动化测试框架 项目说明 本框架是一套基于selenium+Python3.7+yaml+Robot Framework而设计的数据驱动UI自动化测试框架,Robot Framework 作为执行 ...

  10. Spring中如何使用工厂模式实现程序解耦?

    目录 1. 啥是耦合.解耦? 2. jdbc程序进行解耦 3.传统dao.service.controller的程序耦合性 4.使用工厂模式实现解耦 5.工厂模式改进 6.结语 @ 1. 啥是耦合.解 ...