杭电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自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...
 
随机推荐
- 牛客多校第一场 A Equivalent Prefixes 单调栈(笛卡尔树)
			
Equivalent Prefixes 单调栈(笛卡尔树) 题意: 给出两个数组u,v,每个数组都有n个不同的元素,RMQ(u,l,r)表示u数组中[l,r]区间里面的最小值标号是多少,求一个最大的m ...
 - 各技能DBC参数
			
推荐你 通过 引擎的帮助文件查找标准魔法DB 下面是 部分hero引擎的标准魔法DB 34,解毒术,2,26,16,0,0,0,0,0,2,42,50,44,100,46,200,40,, 35,老 ...
 - codeforces div2 603 D. Secret Passwords(并查集)
			
题目链接:https://codeforces.com/contest/1263/problem/D 题意:有n个小写字符串代表n个密码,加入存在两个密码有共同的字母,那么说这两个密码可以认为是同一个 ...
 - 安全文件传输协议之SFTP的使用
			
一.SFTP概述 在前几篇文章,我们讲到了文件传输协议FTP(File Transfer Protocol),那也是使用比较广泛的文件服务器,但是我们需要知道,Linux系统并不自带FTP程序 如果要 ...
 - [Python]python中assert和isinstance的用法
			
assert语句是一种插入调试断点到程序的一种便捷的方式. assert == assert == True assert ( == ) print('-----------') assert ( = ...
 - map-apply-applymap
			
In [1]: import warnings import math import pandas as pd import numpy as np import matplotlib warning ...
 - 抽象工厂模式(JAVA反射)
			
实例代码(JAVA):模式动机 在工厂方法模式中具体工厂负责生产具体的产品,每一个具体工厂对应一种具体产品,工厂方法也具有唯一性,一般情况下,一个具体工厂中只有一个工厂方法或者一组重载的工厂方 ...
 - 第二十九篇 玩转数据结构——线段树(Segment Tree)
			
1.. 线段树引入 线段树也称为区间树 为什么要使用线段树:对于某些问题,我们只关心区间(线段) 经典的线段树问题:区间染色,有一面长度为n的墙,每次选择一段墙进行染色(染色允许覆盖),问 ...
 - VMware 搭建linux虚拟机环境
			
1.任务管理器-服务 确认VMware服务是否启动 2.VMware生成网关地址 编辑--虚拟网络编辑器 VMnet8 NAT设置子网IP,子网掩码,网关 3.windows网络--更改适配器设置-- ...
 - zookeeper and kafka
			
kafka安装前期准备: 1,准备三个节点(根据自己需求决定) 2,三个节点上安装好zookeeper(也可以使用kafka自带的zookeeper) 3,关闭防火墙 chkconfig iptab ...