- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
让我们定义一个要构造的数字的行程,如下所示:访问该数字的最左边的数字。该数字告诉您接下来要访问哪个数字:向右移动,如有必要,环绕到数字的左端,与该数字的值一样多的位置。继续此过程,直到第二次访问某个数字。如果所有数字都已被访问,则该数字符合环绕数字的资格。否则,就不会。
例如,考虑数字32741
。我们访问最左边的数字,它告诉我们接下来访问右侧三个数字,即 4
。接下来我们访问 7
(位于 4
右侧的四个位置),然后访问 1
,然后访问 3
再次。行程第二次回到一个数字,没有访问完所有数字。 (2
从未被访问过。)因此,32741
不是一个环绕数字。另一方面,3233
是一个环绕数字,因为我们首先访问最左边的 3
,然后是最右边的 3
,然后是中间的3
,然后是2
,然后返回到最右边的3
。所有四位数字均已访问。
Write a program that accepts as input a positive number and reports whether or not it is a wrap around number.
输入格式:
Input consists of a single positive number.
假设
Assume that the input number is less than or equal to 400000000.
输出格式:
Refer sample output for formatting details.
示例输入 1:
872
示例输出 1:
872 is a wraparound number
示例输入 2:
351267813
示例输出 2:
351267813 is not a wraparound number.
<小时/>
这是我的程序..它显示示例输入 1 的错误输出和示例输入 2 的正确结果。
#include<stdio.h>
int main()
{
int a[9],number;
scanf("%d",&number);
int i;
for(i=0;i<9;i++)
{
a[i]=-1;
}
int temp=0,digit=0,index=0;
temp=number;
while(temp!=0)
{
digit=(temp%10);
a[index]=digit;
index=index+1;
temp=temp/10;
}
int size=0,checksize=-1;
i=0;
for(i=0;i<9;i++)
{
if(a[i]==-1)
{
size=i;
checksize=0;
break;
}
}
if(checksize==-1)
size=9;
int isAWrapAround=0;
int x=0,count=size-1,remaining=0,arraysize=size;
for(i=(arraysize-1);i>=0;i--)
{
x=a[count];
a[count]=-1;
if(x!=-1)
{
if(count-x>=0)
{
count=count-x;
}
else
{
remaining=x-count;
count=0;
do
{
if(remaining<=arraysize)
{
count=arraysize-remaining;
break;
}
else
{
count=remaining-arraysize;
remaining=remaining-arraysize;
}
}
while(count>arraysize-1);
}
}
else
{
isAWrapAround=-1;
}
}
if(isAWrapAround==0)
{
printf("%i is a wraparound number",number);
}
else
{
printf("%i is not a wraparound number",number);
}
return 0;
}
无法找出错误。
最佳答案
刚刚写了一个简单的代码来演示我如何解决这个问题。采取一些想法并改进你的。干杯
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
//! Max amount of digits in input value
#define maxInputDigits 9
//! Highest input value
static const uint32_t maxInputValue = 400000000;
int main()
{
uint32_t inputValue;
uint8_t digitValue[maxInputDigits], tmpDigitValue[maxInputDigits];
uint8_t nrOfDigits = 0;
bool digitVisit[maxInputDigits] = {false, false, false, false, false, false, false, false, false};
uint32_t dividend = 10;
uint32_t divisor;
uint8_t cnt;
uint8_t index;
uint8_t jumps;
// Get input from user
scanf("%d", &inputValue);
// Input valid?
if ( inputValue > maxInputValue )
{
printf("Input value condition: <= %d", maxInputValue);
}
// Separate all digits from input value into its own index
divisor = inputValue;
while( divisor != 0 )
{
tmpDigitValue[nrOfDigits] = (divisor % dividend)/(dividend / 10);
divisor /= 10;
nrOfDigits++;
}
// Reverse the order, so that the least digit becomes left most in the array (digitValue[0])
for ( cnt = 0; cnt < nrOfDigits; cnt++ )
{
digitValue[cnt] = tmpDigitValue[(nrOfDigits-1)-cnt];
}
printf("Nr of digits: %d\n\n\n", nrOfDigits);
// Set the start index (left most)
index = 0;
// Start the process
while ( true )
{
printf("Current value[index]: %d[%d]\n",digitValue[index], index);
// Already been checked?
if ( digitVisit[index] == true )
{
break;
}
else
{
digitVisit[index] = true;
}
// Amount of jumps
jumps = digitValue[index];
// Jump to next index
while ( jumps > 0 )
{
index = ( index >= (nrOfDigits - 1) ) ? 0 : (index + 1);
jumps--;
}
}
// Check if any of the digits has not been visited
for ( cnt = 0; cnt < nrOfDigits; cnt++ )
{
if ( digitVisit[cnt] == false )
{
printf("\n%d is not a wraparound number\n", inputValue);
return 0;
}
}
printf("%d is a wraparound number\n", inputValue);
return 0;
}
关于c - 识别环绕号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717310/
我正在学习 ada 并且我正在尝试为枚举实现附加重载。 基本上我希望能够向 Day 类型添加一个 Integer 并获得生成的 Day 值。所以星期一 + 2 => 星期三。 这是我的简化代码: pr
Pycharm 具有“包围”代码片段的功能。有一些已经设置好的功能: 我想添加print()(使用python3),我该怎么做? 最佳答案 AFAIU,您可以为此定义自己的“实时”模板。 定义实时模板
例。我有一个包含15个对象的数组。我想从给定的索引开始枚举。假设从索引5开始,然后是上方的索引,下方,上方,下方等的索引...我确实希望它绕起来。 因此,在我的示例中,索引的顺序将是这样。 5、6、4
我需要帮助创建 UIPickerView 来环绕选项。因此,选择器不是这样的: 我希望它看起来像这样(没有“min”): 我到处找,但找不到用 Swift 2.0 实现的方法谢谢! 最佳答案 以下是有
如何让 UITextView 将其文本包裹在 UIImage 周围,如下图所示? 图像大小不一定是事先已知的。 最佳答案 IOS 7 及以上版本: UIBezierPath * imgRect = [
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: UIScrollView. Any thoughts on implementing “infinite” scro
我像这样创建纹理: this->width = width; this->height = height; glGenFramebuffers(1, &framebuffer); glBindFram
在编码和模板化中,我经常需要换行文本的特定部分。是否有任何快捷方式可以包装当前选择,例如: Hello World "Hello World" Hello World {{ trans 'Hello
我正在做一个项目,我们有一些从数据库中填充的 Highcharts 图表;其中之一是散点图,我们需要包围放置在图表外部区域的点。 我们需要像 this 这样的图表但是我们需要散点图外部点周围的区域;使
我有一个 500 像素高和 50 像素宽的 jpg。它由 10 个 50px x 50px 的正方形组成,每个正方形包含一个从 1 到 10 的数字(1 在图像顶部,10 在底部)。 (jpg 在这里
我正在尝试为那些了解它的人创建一个类似 Microsoft Project 的元素控件。 我有一个Container Div,然后有两个子容器如下: 每个子容器都有很多内部 div,例如,我的第一个子
我有 4 个 div,一个我想向左浮动,视频播放器(加载了 jquery),另一个包含一些将向右浮动的帮助/提示文本。这两个应该排在顶部。在视频播放器下方将是一个 div 内的表格。 当有人点击表格中
这个问题在这里已经有了答案: Proper use of flex properties when nesting flex containers (1 个回答) 关闭 4 年前。
我在使用自定义列表图像时遇到问题/其中图标隐藏在列表环绕的 float 元素后面。 http://jsfiddle.net/V8evM/ HTML This is list item n
是否可以将 textview 环绕在 textview 周围,第二个 textview 将环绕到第一个 textview 下的下一行? 例如: 我尝试过使用 android:layout_weig
图片最能说明问题: 它只是一个 float: left 图像 ( http://jsbin.com/itihes/1 )。有什么方法可以防止纯 CSS 中的动态文本出现这个问题吗?我确实希望文本换行,
我在 C 规范中读到一点,无符号变量(特别是 unsigned short int)在整数溢出时执行一些所谓的环绕 ,尽管我在带符号的变量上找不到任何东西,除了我留下了未定义的行为。 我的教授告诉我,
如果您想要容器底部的 div,如何让文本环绕 div? 我可以弄清楚如何让文本环绕在 div 上,只要它在顶部,但如果我尝试将它推到页面底部,文本要么不会'不要继续跨越 div 的顶部,否则 div
假设数组的长度为 1000。我正在尝试创建一种简单的方法来遍历存储在数组中的图像路径而不会越界。当涉及到单击“下一步”按钮以增加数组索引时,下面的方法使用模数很好地处理了环绕,但当我必须减少并从索引中
假设我的光标在单词 word 内.使用 vim-surround,输入序列 ysiw*将替换 word与 *word* . 问题:是否有我可以输入的单个序列来代替生成 **word** (即,单词加粗
我是一名优秀的程序员,十分优秀!