Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位大哥帮忙看下小弟代码,为啥总是wa,

Posted by xcl119xcl at 2007-07-24 23:27:23 on Problem 1317
#include <iostream>
#include <string>
using namespace std;

char fir[75];
int key;
//转换为相应字符的位置
int value(int val,int num)
{
	int i=(val+num)%28;
	if(i>0&&i<27)
		i=i+96;
	else if(i==0)
		i=95;
	else 
		i=46;
	return i;
}
//转换为响应的字符
void change(string str)
{
	int len=str.length();
	int now;//确定现在数据是在哪个位置
	int v;
	for(int i=0;i<len;i++)
	{
		if(str[i]>='a'&& str[i]<='z')
		{
			now=(key*i)%len;
			int a=int(str[i]-'a'+1);
			v=value(a,i);
			fir[now]=char(v);//将字符付值到相应的位置
		}
		else if(str[i]=='_')
		{	
			now=(key*i)%len;
			v=value(0,i);
			fir[now]=char(v);
		}
		else
		{
			now=(key*i)%len;
			v=value(27,i);
			fir[now]=char(v);
		}
	}
	//输出数据
	cout<<fir<<endl;
}
int main()
{
	
	string strend;
	
	cin>>key;
	while(key!=0)
	{
		cin>>strend;change(strend);
		//cout<<endl;		
		cin>>key;
	}
	return 0;
}	

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator