c语言,受怀孕了攻不知道虐受原因 wrong amswer

关于回文的水题,结果为wrong answer解决办法 - C语言当前位置:& &&&关于回文的水题,结果为wrong answer解决办法关于回文的水题,结果为wrong answer解决办法&&网友分享于:&&浏览:0次关于回文的水题,结果为wrong answerA&regular&palindrome&is&a&string&of&numbers&or&letters&that&is&the&same&forward&as&backward.&For&example,&the&string&"ABCDEDCBA"&is&a&palindrome&because&it&is&the&same&when&the&string&is&read&from&left&to&right&as&when&the&string&is&read&from&right&to&left.
A&mirrored&string&is&a&string&for&which&when&each&of&the&elements&of&the&string&is&changed&to&its&reverse&(if&it&has&a&reverse)&and&the&string&is&read&backwards&the&result&is&the&same&as&the&original&string.&For&example,&the&string&"3AIAE"&is&a&mirrored&string&because&"A"&and&"I"&are&their&own&reverses,&and&"3"&and&"E"&are&each&others'&reverses.
A&mirrored&palindrome&is&a&string&that&meets&the&criteria&of&a&regular&palindrome&and&the&criteria&of&a&mirrored&string.&The&string&"ATOYOTA"&is&a&mirrored&palindrome&because&if&the&string&is&read&backwards,&the&string&is&the&same&as&the&original&and&because&if&each&of&the&characters&is&replaced&by&its&reverse&and&the&result&is&read&backwards,&the&result&is&the&same&as&the&original&string.
Of&course,"A","T",&"O",&and&"Y"&are&all&their&own&reverses.
A&list&of&all&valid&characters&and&their&reverses&is&as&follows.
Character Reverse Character Reverse Character Reverse
A A M M Y Y
B & N & Z 5
C & O O 1 1
D & P & 2 S
E 3 Q & 3 E
F & R & 4 &
G & S 2 5 Z
H H T T 6 &
I I U U 7 &
J L V V 8 8
K & W W 9 &
L J X X & &
Note&that&O&(zero)&and&0&(the&letter)&are&considered&the&same&character&and&therefore&ONLY&the&letter&"0"&is&a&valid&character.
Input&consists&of&strings&(one&per&line)&each&of&which&will&consist&of&one&to&twenty&valid&characters.&There&will&be&no&invalid&characters&in&any&of&the&strings.&Your&program&should&read&to&the&end&of&file.
For&each&input&string,&you&should&print&the&string&starting&in&column&1&immediately&followed&by&exactly&one&of&the&following&strings.
STRING CRITERIA
"&--&is&not&a&palindrome." if&the&string&is&not&a&palindrome&and&is&not&a&mirrored&string
"&--&is&a&regular&palindrome." if&the&string&is&a&palindrome&and&is&not&a&mirrored&string
"&--&is&a&mirrored&string." if&the&string&is&not&a&palindrome&and&is&a&mirrored&string
"&--&is&a&mirrored&palindrome." if&the&string&is&a&palindrome&and&is&a&mirrored&string
Note&that&the&output&line&is&to&include&the&-'s&and&spacing&exactly&as&shown&in&the&table&above&and&demonstrated&in&the&Sample&Output&below.
In&addition,&after&each&output&line,&you&must&print&an&empty&line.
===================================================================
Sample&Input
NOTAPALINDROME&
ISAPALINILAPASI&
Sample&Output
NOTAPALINDROME&--&is&not&a&palindrome.
ISAPALINILAPASI&--&is&a&regular&palindrome.
2A3MEAS&--&is&a&mirrored&string.
ATOYOTA&--&is&a&mirrored&palindrome.
==================================================================
#include&&stdio.h&
#include&&stdlib.h&
#include&&string.h&
char&MirroredStr[]={"AE3HILJMO0S2TUVWXYZ518"};
int&IsPalindrome(char&str[])
&&&&int&i,&j;
&&&&len&=&strlen(str);
&&&&for(i&=&0,j&=&len-1;i&&&j;i++,j--)
&&&&&&&&if((str[i]&==&'0'&&str[j]&==&'O')||(str[i]&==&'O'&&str[j]&==&'0'))
&&&&&&&&&&&&
&&&&&&&&if(str[i]&!=&str[j])
&&&&&&&&&&&&return&0;
&&&&return&1;
int&IsMirrored(char&str[])
&&&&int&len,len_
&&&&int&i,j,flag&=&0;
&&&&len&=&strlen(str);
&&&&len_mod&=&strlen(MirroredStr);
&&&&for(i&=&0;i&&&i++)
&&&&&&&&for(j&=&0;j&&&len_j&++)
&&&&&&&&&&&&flag&=&0;
&&&&&&&&&&&&if(str[i]&==&MirroredStr[j])
&&&&&&&&&&&&{
&&&&&&&&&&&&&&&&flag&=&1;
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&}
&&&&&&&&if(flag&!=&1)
&&&&&&&&&&&&return&0;
&&&&return&1;
int&main()
&&&&char&str[1000]&={0};
&&&&int&IsP,IsM;
&&&&while(gets(str))
&&&&&&&&printf("%s&--&",str);
&&&&&&&&IsP&=&IsPalindrome(str);
&&&&&&&&IsM&=&IsMirrored(str);
&&&&&&&&if(IsP&==&0&&&&IsM&==&0)
&&&&&&&&&&&&&printf("is&not&a&palindrome.\n");
&&&&&&&&if(IsP&==&0&&&&IsM&==&1)
&&&&&&&&&&&&printf("is&a&mirrored&string.\n");
&&&&&&&&if(IsP&==&1&&&&IsM&==&0)
&&&&&&&&&&&&printf("is&a&regular&palindrome.\n");
&&&&&&&&if(IsP&==&1&&&&IsM&==&1)
&&&&&&&&&&&&printf("is&a&mirrored&palindrome.\n");
&&&&&&&&printf("\n");
&&&&return&0;
结果输入输出都符合,但不知道为什么是&wrong&answer------解决思路----------------------引用:Quote: 引用:
Quote: 引用:
求帮助%&_&%&我觉得你写的那个挺好的。我在codeblocks上试了下。
问题会不会出在&gets()那里。因为string结尾会是\0。不然改成scanf&来做?&接着IsPalindrome那里的j&=&len-1这类的,都要+1吧。j=len&等等...Sorry,&后面说的话秀下限了...&
另外还发现一个问题。如果什么都不输入&它会显示is&a&mirrored&palin可能这也是个错误。需要把什么都不输入直接敲回车运行改为&--&is&not&palindrome.
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 1234567891011 Copyright & &&版权所有共有 2434 人关注过本帖
标题:求大神。。OJ上说我wrong answer,可是devc++弄出来是对的。用c语言的,数字 ...
来 自:浙江杭州
等 级:新手上路
帖 子:10
结帖率:100%
&&已结贴√
&&问题点数:20&&回复次数:11&&&
求大神。。OJ上说我wrong answer,可是devc++弄出来是对的。用c语言的,数字分析
输入一个不多于5位的正整数,要求:
(1)求出它是几位数;
(2)分别输出每一位数字;
(3)按逆序输出各位数字;
(4)判断逆序后的数字是奇数或偶数,是奇数输出1,是偶数输出0。
注意:最后一行输出后不要再输出回车换行符。
输入样例:
输出样例:
#include &stdio.h&
#include &stdlib.h&
{ int num,num1,indiv,ten,hundred,thousand,ten_thousand,
&&scanf(&%d&,&num);
&&if (num&9999) place=5;
&&else if(num&999) place=4;
&&else if(num&99) place=3;
&&else if(num&9) place=2;
&&else place=1;
&&printf(&%d\n&, place);
&&ten_thousand=num/10000;
&&thousand=num/1000%10;
&&hundred=num/100%10;
&&ten=num%100/10;
&&indiv=num%10;
switch(place)
&&{case 5: printf(&%d %d %d %d %d\n&,ten_thousand,thousand,hundred,ten,indiv);
&&&&&&&&&&&num1=printf(&%d%d%d%d%d\n&,indiv,ten,hundred,thousand,ten_thousand);
&&&&&&&&&&&
&&&case 4: printf(&%d %d %d %d\n&,thousand,hundred,ten,indiv);
&&&&&&&&&&&num1=printf(&%d%d%d%d\n&,indiv,ten,hundred,thousand);
&&&&&&&&&&&
&&&case 3: printf(&%d %d %d\n&,hundred,ten,indiv);
&&&&&&&&&&&num1=printf(&%d%d%d\n&,indiv,ten,hundred);
&&&&&&&&&&&
&&&case 2: printf(&%d %d\n&,ten,indiv);
&&&&&&&&&&&num1=printf(&%d%d\n&,indiv,ten);
&&&&&&&&&&&
&&&case 1: printf(&%d\n&,indiv);
&&&&&&&&&&&num1=printf(&%d\n&,indiv);
&&&&&&&&&&&
&&if(num1%2==0)printf(&0&);
&&else printf(&1&);
&&system(&PAUSE&);&&&
&&return 0;
搜索更多相关主题的帖子:
等 级:贵宾
威 望:103
帖 子:3278
专家分:12654
&&得分:10&
这和你用什么编译器没什么关系。
注意题设4的描述,是判断逆序后的数字的奇偶性,也就是原数最高位的奇偶性。你的num1的值是indiv输入后的长度加1(还有一个换行符),而非题目要求的东西。
还有 system(&PAUSE&);我希望你告诉它是你在测试时加的,提交时没有句。
愿意的话你提交一下下面的代码告诉我结果。
#include&stdio.h&
int main()
&&& int n, a[5], len,
&&& scanf(&%d&, &n);
&&& for(len = 0; n /= 10) a[len++] = n % 10;
&&& if(!len) a[0] = 0, len = 1;
&&& for(i = len, printf(&%d&, a[--i]); printf(& %d&, a[--i]));
&&& puts(&&);
&&& for(i = 0; i & printf(&%d&, a[i++]));
&&& puts(&&);
&&& putchar((a[len - 1] & 1) + '0');
&&& return 0;
重剑无锋,大巧不工
来 自:浙江杭州
等 级:新手上路
帖 子:10
回复 2楼 beyondyf
恩恩。。谢啦。。我知道了。。那个system没上传。传不上去
来 自:浙江杭州
等 级:新手上路
帖 子:10
回复 2楼 beyondyf
printf函数值的返回值了解过了。。
等 级:贵宾
威 望:103
帖 子:3278
专家分:12654
&&得分:10&
是我的描述有误,让你费解了。
你的num1最后的值是逆序后输出字符串的长度,也就是逆序后数值的长度(当然也等于原数的长度)加上一个换行符的长度,因为你的格式化字符串中还包含一个换行符。
这与题意不符。
还没告诉我,你提交我的代码结果,AC了吗?
重剑无锋,大巧不工
来 自:浙江杭州
等 级:新手上路
帖 子:10
回复 5楼 beyondyf
我有回你,你的算法不是c语言的吧?我提交了,结果是wrong answer。。。。。而且我看不懂if(!len)。。以及很多。。我是初学者。。很多都看不懂。。
来 自:浙江杭州
等 级:新手上路
帖 子:10
回复 5楼 beyondyf
AC是什么意思啊?
等 级:贵宾
威 望:103
帖 子:3278
专家分:12654
AC: Accepted
我写的是标准C语言,任何编译器都不会有问题
把这道题的OJ地址发上来,我怀疑你的描述有问题
重剑无锋,大巧不工
来 自:浙江杭州
等 级:新手上路
帖 子:10
回复 8楼 beyondyf
好的。http://61.164.87.150:5480/
来 自:浙江杭州
等 级:新手上路
帖 子:10
回复 8楼 beyondyf
怎么样。。。是wrong answer吧?
版权所有,并保留所有权利。
Powered by , Processed in 0.355355 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved21:05 提问
BP算法的C语言实现,代码个人测试正确, 但是wrong answer, 求大神指点
//#include "user.h"
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#define OUT_COUT 8
//输出向量维数
#define IN_COUT 72
//输入向量维数
#define COUT
//样本数量
#define NN 99
//单个样本数量
typedef struct {
//bp人工神经网络结构
//实际使用隐层数量
//double v[IN_COUT][IN_COUT/3];
//隐藏层权矩阵i,隐层节点最大数量为50
double v[IN_COUT/3][IN_COUT];
//double w[IN_COUT/3][OUT_COUT];
//输出层权矩阵
double w[OUT_COUT][IN_COUT/3];
double b1[IN_COUT/3];
double b2[OUT_COUT];
double x[COUT][IN_COUT];
double y[COUT][OUT_COUT];
//精度控制参数
//最大循环次数
double fnet(double net) { //Sigmoid函数,神经网络激活函数
//return 1/(1+exp(-net));
return 2.0/(1+exp(-net))-1.0;
int InitBp(bp_nn *bp) { //初始化bp网络
/*printf("请输入隐层节点数,最大数为100:\n");
scanf_s("%d", &(*bp).h);
printf("请输入学习率:\n");
scanf_s("%lf", &(*bp).a);
//(*bp).a为double型数据,所以必须是lf
printf("请输入精度控制参数:\n");
scanf_s("%lf", &(*bp).b);
printf("请输入最大循环次数:\n");
scanf_s("%d", &(*bp).LoopCout);*/
(*bp).h = 24;
(*bp).a = 0.4;
(*bp).b = 0.0001;
(*bp).LoopCout = 2000;
srand((unsigned)time(NULL));
for (i = 0; i & (*bp).h; i++)
for (j = 0; j & IN_COUT; j++)
(*bp).v[i][j] = rand() / (double)(RAND_MAX);
(*bp).b1[i] = rand()/(double)(RAND_MAX);
for (i = 0; i & OUT_COUT; i++)
for (j = 0; j & (*bp).h; j++)
(*bp).w[i][j] = rand() / (double)(RAND_MAX);
(*bp).b2[i] = rand()/(double)(RAND_MAX);
int TrainBp(bp_nn *bp, double x[COUT][IN_COUT], double y[COUT][OUT_COUT]) {
//训练bp网络,样本为x,理想输出为y
double f = (*bp).b;
//精度控制参数
double a = (*bp).a;
int h = (*bp).h;
//隐层节点数
//double v[IN_COUT][IN_COUT/3], w[IN_COUT/3][OUT_COUT]; //权矩阵
double v[IN_COUT/3][IN_COUT], w[OUT_COUT][IN_COUT/3]; //权矩阵
double b1[IN_COUT/3],b2[OUT_COUT];
double ChgH[IN_COUT/3], ChgO[OUT_COUT];
//修改量矩阵
double O1[IN_COUT/3], O2[OUT_COUT];
//隐层和输出层输出量
int LoopCout = (*bp).LoopC
//最大循环次数
int i, j, k,
for (i = 0; i & i++)
{// 复制结构体中的权矩阵
for (j = 0; j & IN_COUT; j++)
v[i][j] = (*bp).v[i][j];
b1[i] = (*bp).b1[i];
for (i = 0; i & OUT_COUT; i++)
for (j = 0; j & j++)
w[i][j] = (*bp).w[i][j];
b2[i] = (*bp).b2[i];
double e = f + 1;
for (n = 0; e & f && n & LoopC n++)
{ //对每个样本训练网络
for (i= 0; i & COUT; i++)
for (k= 0; k & k++)
//计算隐层输出向量
for (j = 0; j & IN_COUT; j++)
temp = temp + x[i][j] * v[k][j];
O1[k] = fnet(temp+(*bp).b1[i]);
for (k = 0; k & OUT_COUT; k++)
{ //计算输出层输出向量
for (j = 0; j & j++)
temp = temp + O1[j] * w[k][j];
O2[k] = fnet(temp+(*bp).b2[k]);
for (j = 0; j & OUT_COUT; j++)
{//计算输出层的权修改量
ChgO[j] = O2[j] * (1 - O2[j]) * (y[i][j] - O2[j]);
for (j = 0; j & OUT_COUT ; j++)
{//计算输出误差
e = e + (y[i][j] - O2[j]) * (y[i][j] - O2[j]);
for (j = 0; j & OUT_COUT; j++)
//计算隐层权修改量
for (k = 0; k & k++)
temp = temp + w[j][k] * ChgO[k];
ChgH[j] = temp * O1[j] * (1 - O1[j]);
for (j = 0; j & OUT_COUT; j++)
{//修改输出层权矩阵
for (k = 0; k & k++)
w[j][k] = w[j][k] + a * O1[j] * ChgO[k];
for (j = 0; j & j++)
for (k = 0; k & IN_COUT; k++)
v[j][k] = v[j][k] + a * x[i][j] * ChgH[k];
if (n % 10 == 0)
printf("误差 : %f\n", e);
printf("总共循环次数:%d\n", n);
printf("调整后的隐层权矩阵:\n");
for (i = 0; i & i++) {
for (j = 0; j & IN_COUT; j++)
printf("%f
", v[i][j]);
printf("\n");
printf("调整后的输出层权矩阵:\n");
for (i = 0; i & OUT_COUT; i++) {
for (j = 0; j & j++)
printf("%f
", w[i][j]);
printf("\n");
for (i = 0; i & i++)
{//把结果复制回结构体
for (j = 0; j & IN_COUT; j++)
(*bp).v[i][j] = v[i][j];
(*bp).b1[i] = b1[i];
for (i = 0; i & OUT_COUT; i++)
for (j = 0; j & j++)
(*bp).w[i][j] = w[i][j];
(*bp).b2[i] = b2[i];
printf("bp网络训练结束!\n");
int UseBp(bp_nn *bp) {
//使用bp网络
float Input[IN_COUT];
double O1[50];
double O2[OUT_COUT]; //O1为隐层输出,O2为输出层输出
while (1) {
//持续执行,除非中断程序
printf("请输入3个数:\n");
for (i = 0; i & IN_COUT; i++)
scanf_s("%f", &Input[i]);
for (i = 0; i & (*bp).h; i++) {
for (j = 0; j & IN_COUT; j++)
temp += Input[j] * (*bp).v[j][i];
O1[i] = fnet(temp-(*bp).b1[i]);
for (i = 0; i & OUT_COUT; i++) {
for (j = 0; j & (*bp).h; j++)
temp += O1[j] * (*bp).w[j][i];
O2[i] = fnet(temp-(*bp).b2[i]);
printf("结果:
for (i = 0; i & OUT_COUT; i++)
printf("%.3f ", O2[i]);
printf("\n");
void readFP(double x[COUT][IN_COUT],double y[COUT][OUT_COUT])
//bp_nn bp1;
ifstream fileinput1;
ifstream fileinput2;
ifstream fileinput3;
ifstream fileinput4;
ifstream fileinput5;
ifstream fileinput6;
ifstream fileinput7;
ifstream fileinput8;
fileinput1.open("emgclose.txt");
fileinput2.open("emgopen.txt");
fileinput3.open("emgext.txt");
fileinput4.open("emgfle.txt");
fileinput5.open("emgsph.txt");
fileinput6.open("emgcyl.txt");
fileinput7.open("emgtri.txt");
fileinput8.open("emgkey.txt");
for(int m = 0;m& NN;++m)
for(int i =0;i & IN_COUT;++i)
fileinput1 && x[m][i];
for(int m = NN;m&2*NN;++m)
for(int i =0;i & IN_COUT;++i)
fileinput2 && x[m][i];
for(int m = 2*NN;m&3*NN;++m)
for(int i =0;i & IN_COUT;++i)
fileinput3 && x[m][i];
for(int m = 3*NN;m&4*NN;++m)
for(int i =0;i & IN_COUT;++i)
fileinput4 && x[m][i];
for(int m = 4*NN;m&5*NN;++m)
for(int i =0;i & IN_COUT;++i)
fileinput5 && x[m][i];
for(int m = 5*NN;m&6*NN;++m)
for(int i =0;i & IN_COUT;++i)
fileinput6 && x[m][i];
for(int m = 6*NN;m&7*NN;++m)
for(int i =0;i & IN_COUT;++i)
fileinput7 && x[m][i];
for(int m = 7*NN;m&8*NN;++m)
for(int i =0;i & IN_COUT;++i)
fileinput8 && x[m][i];
fileinput1.close();
fileinput2.close();
fileinput3.close();
fileinput4.close();
fileinput5.close();
fileinput6.close();
fileinput7.close();
fileinput8.close();
fileinput.open("teach.txt");
for (int m2 = 0; m2 & OUT_COUT; m2++)
for (int i = 0; i & OUT_COUT; i++)
fileinput&&y[m2][i];
for (int j = m2*NN; j & (m2+1)*NN; j++)
for (int k = 0; k & OUT_COUT; k++)
y[j][k] = y[m2][k];
for (int i = 0; i & NN; i++)
for (int j = 0; j & OUT_COUT; j++)
y[i][j] = y[0][j];
fileinput.close();
double Mininput[IN_COUT] = {0.0};
double Maxinput[IN_COUT] = {0.0};
//找出训练的数据相应的最大值、最小值,为归一化做准备
for (int i = 0; i & IN_COUT; i++)
Mininput[i] = Maxinput[i] = x[0][i];
for (int j = 0; j & COUT; j++)
Mininput[i] = Mininput[i] & x[j][i]?Mininput[i]:x[j][i];
Maxinput[i] = Maxinput[i] & x[j][i]?Maxinput[i]:x[j][i];
//归一化处理
for (int i = 0; i & OUT_COUT; i++)
for (int j = 0; j & COUT; j++)
y[j][i] = 2.0*(y[j][i] - 0.0)/(1.0 - 0.0)-1.0;
for (int i = 0; i & IN_COUT; i++)
for (int j = 0; j & COUT; j++)
//X[i][j] = (X1[i][j] - Mininput[i]+1)/(Maxinput[i] - Mininput[i]+1);
x[j][i] = 2.0*(x[j][i] - Mininput[i])/(Maxinput[i] - Mininput[i])-1.0;
int main()
/* float x[COUT][IN_COUT] = {{0.8,0.5,0},
{0.9,0.7,0.3},
{1,0.8,0.5},
{0,0.2,0.3},
{0.2,0.1,1.3},
{0.2,0.7,0.8}}; //训练样本
int y[COUT][OUT_COUT] = {{0,1},
//理想输出
readFP(bp.x,bp.y);
InitBp(&bp);
//初始化bp网络结构
TrainBp(&bp, bp.x, bp.y);
//训练bp神经网络
// UseBp(&bp);
//测试bp神经网络
按赞数排序
你试着调整下隐含层节点数,学习率这些参数,其次看看修正权值是否正确
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!
其他相似问题}

我要回帖

更多关于 你不知道的javascript 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信