Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
怎一个水字了得。#include <iostream> #include <string> using namespace std; int main() { string str; int i,j,k,length,sum,num[65]; while (cin>>str) { length = str.size(); for ( i = 0 , sum = 0 ; i < length ; i++) { sum += str[i]-48; } if( sum == 0 ) cout<<str.c_str()<<" is cyclic"<<endl; else if( sum * 2 != 9 * length ) cout<<str.c_str()<<" is not cyclic"<<endl; else { //需要判断顺序是否满足 for ( i = 0 ; i < length ; i++) { num[i] = (str[i]-48)*(length+1); } //进位。 for ( i = length-1 , j = 0 ; i >= 0 ; i--) { k = num[i]+j; j = k/10; num[i] = k%10; if( num[i] != 9 ) break; } if( i == -1 && j == 0 ) cout<<str.c_str()<<" is cyclic"<<endl; else cout<<str.c_str()<<" is not cyclic"<<endl; } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator