如何根据电台时间打印时间?像下午6点将是18。 [英] How do I print time according to station timing? Like 6pm will be 18.
本文介绍了如何根据电台时间打印时间?像下午6点将是18。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int main(){
int i;
char a[11];
for(i=0;i<10;i++)
cin>>a[i];
if(a[8]=='a' || a[8]=='A')
{
for(i=0;i<=7;i++)
cout<<a[i];
}
else if((a[8]=='P' || a[8]==P) && (a[0]==0) && (a[1]==1 || a[1]=='2' || a[1]=='3' || a[1]=='4' || a[1]=='5' || a[1]=='7' || a[1]==7))
{
a[1]=a[1]+2;
a[0]='1';
cout<<a;
}
else if(a[0]=='0'&& (a[1]=='8'|| a[1]=='9'))
{
a[0]='2';
if(a[1]=='8')
a[1]='0';
else
a[1]='1';
cout<<a;
}
else if(a[0]=='1' &&(a[1]=='0'|| a[1]=='1'))
{
a[0]='2';
if(a[1]==0)
a[1]=='2';
else
a[1]='3';
cout<<a;
}
else if(a[0]=='1' && a[1]=='2' && (a[8]=='a' || a[8]=='A'))
{
cout<<"00:00:00";
}
else
{
cout<<"19:05:n45";
}
return 0;
}
我的尝试:
我的代码中没有出错?任何帮助将不胜感激。
What I have tried:
I'm not getting what's wrong in my code? Any help would be appreciated.
推荐答案
为什么你不使用标准C ++库吗? [ ^ ]。
看上去像是一种混乱:
Looks like a muddleheadedness:
> Like 6pm will be 18.
// else if((a[8]=='P' || a[8]==P) && (a[0]==0) && (a[1]==1 || a[1]=='2' || a[1]=='3' || a[1]=='4' || a[1]=='5' || a[1]=='7' || a[1]==7))
else if((a[8]=='P' || a[8]==P) && (a[0]==0) && (a[1]==1 || a[1]=='2' || a[1]=='3' || a[1]=='4' || a[1]=='5' || a[1]=='6' || a[1]=='7'))
你的字符串操作非常混乱,应该很慢。最好使用 std :: string 类及其良好的函数,如输入。
如果您的代码中的某些内容不清楚你应该设置一个断点并使用调试器。
提示:
a)使用标识来提高可读性
b)你最好在你的代码中写一些注释,以使其更容易理解。
c)覆盖输入数据不是一个好主意,生成一个输出字符串。
Your string operations are very confusing and should be slow. You better use the std::string class with its nice functions like for input.
If something in your code is unclear you should set a break point and use the debugger.
tips:
a) use identions for better readability
b) you better write some comments in your code to make it better understandable.
c) overwriting input data is not a good idea, generate a output string.
这篇关于如何根据电台时间打印时间?像下午6点将是18。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文