请教神牛 pku2316 有个地方不懂

ud_willsmith 2010-08-06 11:34:42
题目如下:Language:DefaultSPIN
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4569 Accepted: 2453

Description

Simulate a locked spinner puzzle.

A locked spinner puzzle is a puzzle where you can only change wheels in groups. It is a common puzzle to achieve some value on the spinners by only changing them in the allowed groups.

Imagine a row of D numbered wheels, each labeled sequentially with the digits 0 through 9. This is similar to what is on a briefcase combination lock.

Below this are a series of B buttons with labels that are D digits long. For example, D may be 4 and the labels are 1000 1200 1002 0111 and 0100. Pressing the button labeled 1000 moves the first wheel once, but leaves the others alone, while pressing the button labeled 1002 moves the first wheel once and the fourth wheel twice, leaving the center wheels unchanged.

Your task is to simulate such a locked spinner puzzle giving the final readout of the wheels.
Input

The input to your program will be a line containing D digits (at most 10) representing the starting positions of the wheels. Following this, each line will have the button label for which button is pressed next.There will always be at least 1 digit

Output

Output the final positions of the wheels.
Sample Input

0001
1003
0206
0034
1111
1003

Sample Output

3348

用c++做的代码:
#include<iostream>
#include<string>
using namespace std;
int main()
{
int array[10];
for (int s=0;s<10;++s)
array[s]=0;
string str;
while (cin>>str)
{
for (int s=0;s<str.length();++s)
array[s]+=str[s]-'0';
}

for (int s=0;s<length;++s)
array[s]=array[s]%10;

for (int s=0;s<length;++s)
cout<<array[s]<<endl;

return 0;
}
在执行时 只能不断输入,却没办法在输入完成后执行程序,请教该如何改???
...全文
69 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
brookmill 2010-08-06
  • 打赏
  • 举报
回复
还有一个办法:用一个特殊的字符串标记输入结束,比如输入"0000"表示结束,然后在代码里做判断。
brookmill 2010-08-06
  • 打赏
  • 举报
回复
如果是windows,输入所有的数字之后,按Ctrl+z
linux按Ctrl+d

64,282

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧