杭电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自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...
随机推荐
- MySQL学习(十一)double write 介绍 (半原创)
复习 Innodb关键的特性 插入缓存 两次写 异步IO 刷新邻近页 自适应哈希索引 概述 double write 的主要的作用是保证写入数据库文件的可靠性.通俗地说就是一份数据写两个地方,当出现异 ...
- Linux新建用户,切换后只显示$问题
1,执行以下命令创建一个新的用户 useradd -d /home/sam -m sam -s /bin/sh -g group -G adm,root 这个命令中指定了这个用户登录的shell 是/ ...
- 每天进步一点点------Allegro PCB命名规则
PCB命名规则-allegro 一.焊盘命名规则 1. 贴片矩形焊盘 命名规则:SMD+长(L)+宽(W)(mil) 举例:SMD90X60 2. 贴片圆焊盘 命名规则:SMDC+焊盘直径(D) ...
- python调用c/c++ (入参出参为指针)
python可以使用ctypes库调用c++编译的so库函数 0x01 c/c++编译为so库文件 编译C文件 gcc -o libpycallfoo.so -shared -fPIC rsa.c ...
- python之nosetest
nose介绍 nose下载 nose使用 -s 能够打印用例中的print信息 ➜ func_tests git:(master) ✗ nosetests -v test_app.py:TestApp ...
- weinre 真机调试
1.在任意文件夹 安装weinre cnpm -g install weinre 2.启动 weinre --httpPort 8009 --boundHost -all- 3.在你的页面中加入 本机 ...
- linux默认的目录结构
/: 根目录/root: root账户的home目录/home: 用户的目录,每个用户有一个home/bin: 可执行文件和命令/lib: 库文件/etc: 配置文件存放地/usr: 用户的应用程序和 ...
- AC自动机讲解超详细
begin:2019/5/2 感谢大家支持! AC自动机详细讲解 AC自动机真是个好东西!之前学KMP被Next指针搞晕了,所以咕了许久都不敢开AC自动机,近期学完之后,发现AC自动机并不是很难,特别 ...
- 最新版的 vscode 怎么配置 Python?
请进 -- > https://www.zhihu.com/question/322530705/answer/860418884
- 【代码学习】PYTHON 线程
一.使用threading模块多线程执行 可以明显看出使用了多线程并发的操作,花费时间要短很多 创建好的线程,需要调用start()方法来启动 #coding=utf-8 import threadi ...