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

    yum install -y tar 查看版本 tar --version

  2. python夜记

    关于多行字符串(multi-line strings)的表现: Python列表是基于0索引的.(zero-indexed). 晌午起床来嘞,再来些笔记: Treasures 1: 列表方法rever ...

  3. Redis 基本数据类型以及相应操作

    〇.常用命令 select <num> 选择库0~15 默认0号库 key * 查看当前库所有键(可以接正则表达式) exists <key> type <key> ...

  4. linux中systemctl详细理解及常用命令

    linux中systemctl详细理解及常用命令 https://blog.csdn.net/skh2015java/article/details/94012643 一.systemctl理解 Li ...

  5. Wx-mpvue开发小程序

    一.准备 安装Node 安装vue-cli  ( npm install --global vue-cli ) 二.创建 初始化项目 ( vue init mpvue/mpvue-quickstart ...

  6. supervisor的使用点滴

    supervisor的安装 pip install supervisor 安装成功后步骤 1.创建配置文件 echo_supervisord_conf  > /etc/supervisord.c ...

  7. RLE压缩算法详解

    from:http://data.biancheng.net/view/152.html RLE压缩算法(下简称RLE算法)的基本思路是把数据按照线性序列分成两种情况:一种是连续的重复数据块,另一种是 ...

  8. Go计时器

    1. NewTimer package main import ( "time" "fmt" ) func main() { /* 1. func NewTim ...

  9. 修改eclipse工程jdk版本

    在eclipse中项目jdk版本不匹配的时候需要修改项目工程的jdk版本,但是网上的一些版本修改不是很完全,经过一些摸索之后,参考总结了我在项目中的具体配置实践 问题: 修改eclipse中的项目jd ...

  10. jq的 on 事件委托 导致多次执行问题

    解除 这个元素 在 父级上的 click 事件委托$(msg.fatherDiv).off('click','.fangdaimg_fn2'); click事件$('.fangdaimg_fn2'). ...