poj 3157 Java vs C++ 模拟

题意:

将java和c++中的变量名相互转换,比如:long_and_mnemonic_identifier装换为longAndMnemonicIdentifier。

思路:

直接模拟遍历替换,陷阱很多。。

代码:

//poj 3157
//sep9
#include <iostream>
using namespace std;
char s[256],ans[256];

void deal()
{
	int i,j;
	int style1=0,style2=0;
	for(i=0;s[i]!='\0';++i)
		if(s[i]=='_')
			style1=1;
		else if('A'<=s[i]&&s[i]<='Z')
			style2=1;
	if(style1+style2==2){
		printf("Error!\n");
		return;
	}
	for(i=0,j=0;s[i]!='\0';)
		if('a'<=s[i]&&s[i]<='z')
			ans[j++]=s[i++];
		else if(s[i]=='_'){
			if(s[i+1]=='\0'||i==0||s[i+1]=='_'){
				printf("Error!\n");
				return ;
			}
			else{
				++i;
				ans[j++]=s[i++]-'a'+'A';
			}
		}else if('A'<=s[i]&&s[i]<='Z'){
			if(j==0){
				printf("Error!\n");
				return ;
			}
			ans[j++]='_';
			ans[j++]=s[i++]-'A'+'a';
		}else{
			printf("Error!\n");
			return ;
		}
	ans[j]='\0';
	printf("%s\n",ans);
}

int main()
{
	while(scanf("%s",&s)==1)
		deal();
	return 0;
} 
时间: 2024-10-19 23:32:25

poj 3157 Java vs C++ 模拟的相关文章

POJ 3087 Shuffle&#39;m Up (模拟+map)

题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s1,最顶的c块牌归为s2,依此循环下去. 现在输入s1和s2的初始状态 以及 预想的最终状态s12.问s1 s2经过多少次洗牌之后,最终能达到状态s12,若永远不可能相同,则输出"-1". 解题思路:照着模拟就好了,只是判断是否永远不能达到状态s12需要用map,定义map<

java中多线程模拟(多生产,多消费,Lock实现同步锁,替代synchronized同步代码块)

import java.util.concurrent.locks.*; class DuckMsg{ int size;//烤鸭的大小 String id;//烤鸭的厂家和标号 DuckMsg(){ } DuckMsg(int size, String id){ this.size=size; this.id=id; } public String toString(){ return id + " 大小为:" + size; } } class Duck{ private int

POJ 1027 The Same Game(模拟)

题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluster,同时cluster含有至少两个球),每次选择cluster中包含同色球最多的进行消除,每次消除完之后,上边的要往下移填满空的地方,一列上的球移动之前与之后相对位置不变,如果有空列,右边的列往左移动,每一列相对位置不变 . 思路 : 模拟......不停的递归..... 1 ////POJ 102

POJ 3282 Ferry Loading IV(模拟,队列)

题意   汽车通过渡船过河  渡船开始在左边   输入按车辆来的顺序输入河两岸的车   渡船每次运输的汽车的总长度不能超过渡船自己本身的长度  先来的车先走   求轮船至少跨河多少次才能将所有的车辆都运完 简单模拟  建两个队列  分别装左边的车  和右边的车   算出两边各至少需要运输多少次就行了 #include<cstdio> #include<cstring> #include<queue> using namespace std; int main() { i

POJ 2424 Flo&#39;s Restaurant 模拟

Flo's Restaurant Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2923   Accepted: 916 Description Sick and tired of pushing paper in the dreary bleary-eyed world of finance, Flo ditched her desk job and built her own restaurant. In the s

POJ题目Java代码(一)

POJ 1001 Exponentiation import java.math.BigDecimal; import java.util.Scanner; public class Poj1001 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ BigDecimal bigDecimal = new BigDecimal(sc.next())

poj 1008:Maya Calendar(模拟题,玛雅日历转换)

Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, profes

POJ 3087 Shuffle&#39;m Up(模拟)

Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several

poj 3087 Shuffle&#39;m Up (模拟过程)

Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several